AngularJS——AngularJS实现地址栏取值

有时候我们由如下需求

  • 1、从a.html跳转到b.html
  • 2、从a跳转时携带参数和值、
  • 3、从b.html中取出传过来的参数值

在AngularJS的操作如下

在a.html中添加

<a href='b.html#?test=5'>跳转到b.html</a>

此处注意,使用AngularJS传递参数必须使用#?传递参数,否则将无法接收。

b.html中的AngularJS代码

var id = $location.search()['test'];

id的值即为获得的传过来的test的值

JS——JS实现地址栏取值

原文地址:https://www.cnblogs.com/kitor/p/11298977.html