I have the following code in my service:
testApp.service('detailsService',['databaseService', 'loggedService', '$http', function(databaseService, loggedService, $http){
    var details;
    this.getDetails = function(name){
        return $http({
            method : "GET",
            url : name    
        }).then(function(response) {
           details= response.data;
           console.log(response.data);
           return response.data;
        });
    };
}]);
What i want to do is call this function in my controller when the page(view) is loaded.
testApp.controller('testController', ['$scope', '$location', 'databaseService','detailsService', '$routeParams', function($scope, $location, databaseService, $routeParams, detailsService){
    $scope.details;
    var selectedDetails = function(name){
             detailsService.getDetails(name).then(function(data){
            $scope.details= data;
        });
    };
    selectedDetails(name);
}]);
I keep getting the error detailsService.getDetails is not a function. I'm using the same function from the detailsService in another controller without any problems.
Does anybody know why i keep getting this error?
The error is expected as you are not injecting dependencies properly, You need to use the correct sequence.
testApp.controller('testController', ['$scope', 
    '$location', 
    'databaseService',
    'detailsService', 
    '$routeParams', 
    function($scope, $location, databaseService, detailsService, $routeParams ){
instead of
testApp.controller('testController', ['$scope', 
    '$location', 
    'databaseService',
    'detailsService', 
    '$routeParams', 
    function($scope, $location, databaseService, $routeParams, detailsService){
Note Both the string part and the function arguments need to match up 1:1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With