问题描述
关于$ location.search的说,
Regarding $location.search, the docs say,
返回搜索部分(如对象)当前URL时不带任何参数调用。
在我的网址,我的查询字符串有一个参数?test_user_bLzgB'无值。也'$ location.search()返回一个对象。我如何获得的实际文本?
In my url, my query string has a param '?test_user_bLzgB' without a value. Also '$location.search()' returns an object. How do I get the actual text?
推荐答案
不知道是否已经改变,因为公认的答案被接受,但却是可能的。
Not sure if it has changed since the accepted answer was accepted, but it is possible.
$ location.search()
将返回键 - 值对,同样对作为查询字符串的对象。没有值的一个关键是刚刚存储在对象为真。在这种情况下,对象将是:
$location.search()
will return an object of key-value pairs, the same pairs as the query string. A key that has no value is just stored in the object as true. In this case, the object would be:
{"test_user_bLzgB": true}
您可以用 $ location.search()。test_user_bLzgB
示例(具有较大的查询字符串):<一href=\"http://fiddle.jshell.net/TheSharpieOne/yHv2p/4/show/?test_user_bLzgB&somethingElse&also&something=Somethingelse\">http://fiddle.jshell.net/TheSharpieOne/yHv2p/4/show/?test_user_bLzgB&somethingElse&also&something=Somethingelse
Example (with larger query string): http://fiddle.jshell.net/TheSharpieOne/yHv2p/4/show/?test_user_bLzgB&somethingElse&also&something=Somethingelse
注:由于哈希(因为它会去
As pointed out in the comments by @Naresh and @DavidTchepak, the $locationProvider
also needs to be configured properly: https://code.angularjs.org/1.2.23/docs/guide/$location#-location-service-configuration
这篇关于充分利用查询字符串值使用AngularJS $位置的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!