[英]Use Azure mobile service in Angular phonegap app
I'm new to angularJS, and I'm trying to figure out the way to use azure mobile service in angularJS phonegap app. 我是angularJS的新手,我试图找出在angularJS phonegap应用程序中使用Azure移动服务的方法。 I found this "angular-azure-mobile-service" https://github.com/TerryMooreII/angular-azure-mobile-service/ but was stuck on the third step:
我找到了这个“ angular-azure-mobile-service” https://github.com/TerryMooreII/angular-azure-mobile-service/,但是停留在第三步:
angular.module('myapp', ['myApp.controllers', 'myApp.services', 'azure-mobile-service.module']);
And this is my original code: 这是我的原始代码:
(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;
});
})();
And here is my file structure: http://1drv.ms/1yA6VmF 这是我的文件结构: http : //1drv.ms/1yA6VmF
How can I use this "angular-azure-mobile-service" in my project? 如何在我的项目中使用此“ angular-azure-mobile-service”? Any help would be appreciated!
任何帮助,将不胜感激! Thanks!!
谢谢!!
First of all add an Angular constant to your module 首先向模块添加一个Angular常量
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>',
})
Next, add the Azureservice to your controller, service etc. 接下来,将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);
});
}
})
Dependency Injection ensures that the azure-mobile-service.module is injected into your 'myApp.service'. 依赖注入可确保将azure-mobile-service.module注入到“ myApp.service”中。 You can then use an of the Azureservice methods to access your data.
然后,您可以使用Azure服务方法之一来访问数据。
PLEASE NOTE: the AzureMobileServiceClient name and Azureservice object name must be specified as per the README.md file otherwise the DI will fail. 请注意:必须根据README.md文件指定AzureMobileServiceClient名称和Azureservice对象名称,否则DI将失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.