下决心是可以附加在两个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) –