我在我的路由.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