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將失敗。

相關問題