簡體   English   中英

在Angular phonegap應用中使用Azure移動服務

[英]Use Azure mobile service in Angular phonegap app

我是angularJS的新手,我試圖找出在angularJS phonegap應用程序中使用Azure移動服務的方法。 我找到了這個“ angular-azure-mobile-service” https://github.com/TerryMooreII/angular-azure-mobile-service/,但是停留在第三步:

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”? 任何幫助,將不勝感激! 謝謝!!

首先向模塊添加一個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>',
    })

接下來,將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-mobile-service.module注入到“ myApp.service”中。 然后,您可以使用Azure服務方法之一來訪問數據。

請注意:必須根據README.md文件指定AzureMobileServiceClient名稱和Azureservice對象名稱,否則DI將失敗。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM