Getting values from query string in an url using AngularJS $location

后端 未结 9 952
鱼传尺愫
鱼传尺愫 2020-11-27 04:36

Regarding $location.search, the docs say,

Return search part (as object) of current url when called without any parameter.

In my

9条回答
  •  暖寄归人
    2020-11-27 05:09

    First make the URL format correct for getting the query string use #?q=string that works for me

    http://localhost/codeschool/index.php#?foo=abcd
    

    Inject $location service into the controller

    app.controller('MyController', [ '$location', function($location) { 
    
        var searchObject = $location.search();
    
        // $location.search(); reutrn object 
        // searchObject = { foo = 'abcd' };
    
        alert( searchObject.foo );
    
    } ]);
    

    So the out put should be abcd

提交回复
热议问题