搜索网址参数角JS [英] Search URL parameters with Angular JS
本文介绍了搜索网址参数角JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有这样的网址:
www.mysite.com?account=23&token=asdu756sdg65sdf
现在,我需要单独使用角JS 访问这些URL的参数。
Now, I need to access those URL parameters individually using Angular JS.
我试过使用 location.search
我的控制器内的:
I've tried using location.search
inside my controller:
console.log(location.search);
这很好地返回完整的查询字符串:
Which nicely returns the full query string:
?account=23&token=asdu756sdg65sdf
但似乎返回一个字符串,而不是一个对象。有一种简单的方法来访问字符串中的个人ID和价值?
But it seems to return a string, not an object. Is there an easy way to access the individual ids and values in the string?
我也试过:
console.log($location.search());
这似乎返回一个空的对象。
Which seems to return an empty object.
推荐答案
与尝试
var account = ($location.search()).account;
但是URL应该像/#!/?帐号= 1
but the url should be like /#!/?account=1
这篇关于搜索网址参数角JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文