我在我的路由.state中解析了我在哪里返回一个列表(来自服务器的数据),它是在console.log中定义的.state路由中定义的,但是在控制器中它未定义console.log它。我正在与离子1和AngularJS合作。
路线在控制器中未定义的解析属性
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl',
controllerAs: 'appcn',
resolve: {
notificationsResolve: function ($http) {
$http.defaults.headers.common.Authorization = "Basic MzEwMzIzOjEyMw==";
return $http.get("http://192.168.178.24:8090/notifications/")
.then(function (response) {
return response.data;
});
}
}
})
控制器
angular.module( 'starter.controllers',[ 'appServiceAPI'])
.controller('AppCtrl', ['notificationService', function($ionicModal, $timeout, notificationsResolve,
notificationService) {
var vm = this;
console.log("resolve: " + notificationsResolve);
vm.notifications = notificationsResolve;
正是这...这是问题,多使用插件做这个任务,而不是搞乱它1000倍,被混淆,每次更好。 – shaunhusain
谢谢!两个答案都是正确的,但对于这个建议,我会将其标记为已接受 – Merv