1

I am getting an undefined error for $location. I've been staring at this for too long and need an extra pair of eyes to tell me what I am doing wrong. Thank you.

Controller Example:

myApp.controller('testCtrl', ['$scope', 'GeolocationSvc', '$http', '$location', function ($scope, geolocation, $http, $location, uiGmapGoogleMapApi)

    $scope.test = function ($location){
       $location.search('test', 0);
    }
]);

Error:

Cannot read property 'search' of undefined

2 Answers 2

1

Remove $location from search function parameter, By having $location parameter over there killing the existence of $location dependency instance inside a function.

$scope.test = function (){
   $location.search('test', 0);
}
Sign up to request clarification or add additional context in comments.

2 Comments

@clo_ Glad to help you, Thanks :)
I used your method. My URL already contained the test param with a value of 1. This method added #?test=0 to the end of my current url. I simply want to update the current test param or add it if it does not exist. Do you think this is this the right method?
0

No need to pass it into the function:

myApp.controller('testCtrl', ['$scope', 'GeolocationSvc', '$http', '$location', function ($scope, geolocation, $http, $location, uiGmapGoogleMapApi)

    $scope.test = function (){
       $location.search('test', 0);
    }
]);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.