嗨在我的第一個角度項目工作,我遇到了這個問題,無法看到從我的控制器之一使用服務的價值。
也characterService.query()是精止的errorMessage的值沒有顯示出來
感謝您的幫助
服務:
angular.module('characterResource',['ngResource'])
.factory('characterService',['$resource',function($resource){
var self = this;
self.errorMessage = false;
return $resource('http://gateway.marvel.com:80/v1/public/characters?limit=90&apikey=APIKEY',null, {
query: {
method: 'GET',
isArray: false,
transformResponse: function(data) {
return angular.fromJson(data).data;
},
interceptor:{
responseError:function(error){
console.log(error);
self.errorMessage = true;
}
}
}
});
}]);
控制器:
angular.module('CharactersCtrl', []).controller('CharactersController',['characterService', function(characterService) {
var self = this;
self.sortType = 'name'; // set the default sort type
self.sortReverse = false; // set the default sort order
//self.search = ' '; // set the default search/filter term
self.errorMessage = characterService.errorMessage;
console.log(characterService.errorMessage);
self.init = function(){
self.getCharacters();
}
self.getCharacters = function(){
self.characters = characterService.query();
}
self.init();
}]);
創建plunker複製的問題,添加您的視圖代碼也 – Sajeetharan