0

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

}]);
1
  • 3
    getFollowup takes $http as input argument. remove it. Commented Dec 13, 2016 at 17:26

1 Answer 1

1

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;
}]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.