admin管理员组文章数量:1403500
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) {
本文标签: javascriptlocationsearch() is not workingAngularJs 15Stack Overflow
版权声明:本文标题:javascript - $location.search() is not working - AngularJs 1.5 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744380174a2603462.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论