This article is about creating CURD operation on Azure Mobile Service (WAMS) from angular js web application.
To make CURD operation on AMS from Angular JS, you need to make reference of two main JS file
1: JS provided by Microsoft for AMS.
2: the extended JS for Microsoft AMS
To reference Azure Mobile Services in the controller, change the first line of Controller JS File and add a dependency to ‘azure-mobile-service.module’:
angular.module(
'usersApp'
, [
'azure-mobile-service.module'
])
Add a constant to the bottom of the Controller file with the URL of the Azure mobile site and the application key retrieved from Azure portal. The AMS library will use these to access the AMS site:
).constant(
'AzureMobileServiceClient'
, {
API_URL:
"https://usermobileservice.azure-mobile.net/"
,
API_KEY:
"<APIKEY>"
});
vm.addUser =
function
() {
if
(vm.user.fullname !==
''
) {
Azureservice.insert(
'Users'
"fullname"
: vm.user.fullname,
"mobile"
: vm.user.mobile ,
"email"
: vm.user.email ,
"location"
: vm.user.location ,
"summary"
: vm.user.summary
}).then(
(newitem) {
vm.users.push(newitem);
}
vm.updateUser =
(user) {
user.editMode =
false
;
Azureservice.update(
"id"
: user.id,
: user.fullname,
: user.mobile ,
: user.email ,
: user.location ,
: user.summary
List the users form Angular App. Init function of controller will list all users of AMS user table.
vm.init =
(){
Azureservice.query(
,{})
.then(
(items) {
vm.users = items;
vm.deleteUser =
Azureservice.del(
: user.id
vm.users.splice(vm.users.indexOf(user), 1);
You can check the data from Azure portal also.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://usermobileservice.azure-mobile.net/tables/Users?$inlinecount=allpages. (Reason: CORS header 'Access-Control-Allow-Origin' missing).
You can configure cross-origin resource from Azure portal dashboard. It allows wildcards if required .
MSDN Gallery