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.
Of 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) {
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