Reputation: 352
I am attempting to retrieve a dummy JSON file but I continually get the 'TypeError Cannot read property of 'get' undefined.
What appears to be the issue here?
Module:
angular.module('followup',['followupSearch']);
Factory:
angular.module('followup')
.factory('followupStore', ['$http', function($http) {
var followup = {};
followup.getFollowup = function($http) {
return $http.get('https://jsonplaceholder.typicode.com/posts');
};
return followup;
}]);
Controller:
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
}]);
Upvotes: 0
Views: 549
Reputation: 983
Just remove the argument on the factory function. It will work because you already injected the $http
service in the factory:
angular.module('followup')
.factory('followupStore', ['$http', function($http) {
var followup = {};
followup.getFollowup = function() {
return $http.get('https://jsonplaceholder.typicode.com/posts');
};
return followup;
}]);
Upvotes: 1