I want to get the query string values. I am using $location.search() to get those values but it says that $location.search is not a function. I am using 1.5 version of AngularJs.
JS -
var app = angular.module('myApp', []);
app.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode(true);
}]);
app.controller('myCtrl',[ '$location','$scope', function($scope, $location){
var searchObject = $location.search();
console.log('searchObject');
console.log(searchObject);
}]);
I don't understand what I am missing in the code.
I want to get the query string values. I am using $location.search() to get those values but it says that $location.search is not a function. I am using 1.5 version of AngularJs.
JS -
var app = angular.module('myApp', []);
app.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode(true);
}]);
app.controller('myCtrl',[ '$location','$scope', function($scope, $location){
var searchObject = $location.search();
console.log('searchObject');
console.log(searchObject);
}]);
I don't understand what I am missing in the code.
Share Improve this question edited Jan 30, 2016 at 12:27 Smita Ahinave 1,8887 gold badges26 silver badges42 bronze badges asked Jan 30, 2016 at 12:22 sajalsurajsajalsuraj 99217 silver badges34 bronze badges1 Answer
Reset to default 7Of course it's not a function, because you are calling search
method on the $scope
object. The order of the services you inject into controller is $location
then $scope
. So what you called $location
in controller is actually a $scope
. Order is important.
Correct dependency injection should be:
[ '$location', '$scope', function($location, $scope) {