1

我是angularJS新手,我试图找出在angularJS phonegap应用中使用azure移动服务的方式。我发现这个“角Azure的移动服务” https://github.com/TerryMooreII/angular-azure-mobile-service/但被卡在第三步:在Angular phonegap应用中使用Azure移动服务

angular.module('myapp', ['myApp.controllers', 'myApp.services', 'azure-mobile-service.module']); 

这是我原来的代码:

(function(){ 
'use strict'; 
var module = angular.module('app', ['onsen']); 

module.controller('AppController', function($scope, $data) { 
$scope.doSomething = function() { 
    setTimeout(function() { 
    alert('tappaed'); 
    }, 100); 
}; 
}); 
module.controller('DetailController', function($scope, $data) { 
$scope.item = $data.selectedItem; 
}); 

module.controller('MasterController', function($scope, $data) { 
$scope.items = $data.items; 

$scope.showDetail = function(index) { 
    var selectedItem = $data.items[index]; 
    $data.selectedItem = selectedItem; 
    $scope.ons.navigator.pushPage('detail.html', {title : selectedItem.title}); 
}; 
}); 

module.factory('$data', function() { 
    var data = {}; 

    data.items = [ 
     { 
      title: 'Item 1 Title', 
      label: '4h', 
      desc: 'Lorem ipsum dolor sit amet' 
     }, 
     { 
      title: 'Another Item Title', 
      label: '6h', 
      desc: 'Ut enim ad minim veniam.' 
     }, 
     { 
      title: 'Yet Another Item Title', 
      label: '1day ago', 
      desc: 'Duis aute irure ' 
     }, 
     { 
      title: 'Yet Another Item Title', 
      label: '1day ago', 
      desc: 'Duis aute irure.' 
     } 
    ]; 

    return data; 
}); 
})(); 

这里是我的文件结构: http://1drv.ms/1yA6VmF

我该如何在我的项目中使用这个“angular-azure-mobile-service”?任何帮助,将不胜感激!谢谢!!

回答

1

首先添加一个角度不变,以你的模块

angular.module('myapp', ['azure-mobile-service.module']) 
    .constant('AzureMobileServiceClient', { 
     API_URL : 'https://<your-azure-service>.azure-mobile.net/', 
     API_KEY : '<your-azure-service-API-KEY>', 
    }) 

接下来,添加Azureservice到控制器,服务等

.service('myApp.service', function(Azureservice) { 
     this.init = function() { 
      /* Replace the <my-table-name> with the name of the table in your Azure database. You can use any of the Azureservice methods at this point */ 
      Azureservice.getAll('<my-table-name>') 
      .then(function(items){ 
       $scope.items = items; 
      }, function(err){ 
       console.error(err); 
      }); 

     } 
    }) 

依赖注入保证了Azure的移动服务.module被注入到你的'myApp.service'中。然后,您可以使用Azureservice方法来访问您的数据。

请注意:AzureMobileServiceClient名和Azureservice对象名称必须指定为每README.md文件,否则DI将失败。

相关问题