下決心是可以附加在兩個ngRoute路線和更強大的UI router.but決心不能運作良好的屬性。無法加載數據使用解決AngularJS路線不工作
.factory("Init", function($cordovaContacts) {
var contacts = []; //variable that holds contacts, returned from getContacts
return {
getContacts: function() {
var options = {};
options.filter = "";
options.multiple = true;
//get the phone contacts
$cordovaContacts.find(options).then(function(result) {
contacts = result;
}, function(err) {});
return contacts;
}
}
})
路線
.state('app.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'views/home/home.html',
controller: 'homeController',
resolve: {
getContacts: function(Init) {
return Init.getContacts();
}
}
}
}
})
Controller.js
app.controller("homeController", function (message) { $scope.greeting = getContacts; console.log($scope.greeting); });
你能告訴我,你爲什麼要注入的消息,在控制器的依賴? – kaushlendras
我這樣寫。 app.controller( 「HomeController的」 功能($範圍,初始化,消息){$ scope.greeting = Init.getContacts;執行console.log($ scope.greeting) –