我正在尝试检索一个虚拟JSON文件,但我不断得到'TypeError无法读取'get'未定义的属性。
这里的问题似乎是什么?
模块:
angular.module('followup',['followupSearch']);
厂:
angular.module('followup')
.factory('followupStore', ['$http', function($http) {
var followup = {};
followup.getFollowup = function($http) {
return $http.get('https://jsonplaceholder.typicode.com/posts');
};
return followup;
}]);
控制器:
angular.module('followupSearch')
.controller('followupSearchCtrl', ['$http','followupStore', function($http, followupStore) {
var self = this;
self.getFollowup = getFollowup;
// Get followup
function getFollowup() {
followupStore.getFollowup()
.then(function (response) {
console.log('success');
}, function (error) {
console.log('error');
});
} //getFollowup
}]);
答案 0 :(得分:1)
只需删除工厂功能的参数即可。它会起作用,因为您已经在工厂中注入了$http
服务:
angular.module('followup')
.factory('followupStore', ['$http', function($http) {
var followup = {};
followup.getFollowup = function() {
return $http.get('https://jsonplaceholder.typicode.com/posts');
};
return followup;
}]);