简体   繁体   English

在Angular phonegap应用中使用Azure移动服务

[英]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.

相关问题 移动角度ng-view在PhoneGap应用程序上不起作用 - Mobile Angular ng-view doesn't work on PhoneGap App 带有Rails API Web服务Auth的Angular / Ionic / Phonegap应用 - Angular/Ionic/Phonegap app with rails API web service Auth Angular Azure移动服务客户端API密钥用法 - Angular Azure Mobile Service Client API Key Usage Angular Animations和Phonegap无法在移动设备上运行 - Angular Animations and Phonegap not running on mobile Azure移动服务身份验证可以在网页中运行,而不是在Cordova应用程序中? - Azure mobile service authentication works in web page not in Cordova app? 如何将Azure Mobile Service与Cordova Project AngularJS和C#一起使用? - How to use Azure Mobile Service with Cordova Project AngularJS and C#? Azure应用程序服务上托管的Angular应用程序仅在chrome上崩溃 - angular app hosted on azure app service crashes on chrome only 在Phonegap / ApacheCorova和Ionic框架中构建移动应用程序是否必须使用Angular.js? - Does Angular.js is must for building mobile app in Phonegap/ApacheCorova and Ionic framework? mobile-angular-ui + laravel到phonegap - mobile-angular-ui + laravel to phonegap 同一Azure应用服务中的Java API和angular SPA - java API and angular SPA in the same Azure App Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM