【发布时间】:2017-04-28 20:43:04
【问题描述】:
我正在尝试检索一个虚拟 JSON 文件,但我不断收到 'TypeError Cannot read property of 'get' undefined.
这似乎是什么问题?
模块:
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
}]);
【问题讨论】:
-
getFollowup将 $http 作为输入参数。删除它。
标签: javascript angularjs components