Yoo*_*rek 6 angularjs angular-ui-router
我正在使用查询系统,允许用户从动态字段列表构建查询,我想在URL中持久查询.
通常我会这样做:
$stateProvider.state('alerts', {
url: '/alerts/list?p1&p2&p3'
})
Run Code Online (Sandbox Code Playgroud)
在控制器中我可以用$ stateParam读取params:
console.log($stateParams.p1)
Run Code Online (Sandbox Code Playgroud)
我可以在URL中保存查询:
$state.go($state.current, {p1:'1', p2: '2'}, {location: true, inherit:true, notify:false})
Run Code Online (Sandbox Code Playgroud)
但问题是我不能宣布所有的参数.
我想要做:
$state.go($state.current, {p1:'1', p2: '2', p3:'3', p4: '4', p5:'5'}, {location: true, inherit:true, notify:false})
Run Code Online (Sandbox Code Playgroud)
但是ui-router忽略了没有声明状态的params.
我知道$ location.search让我可以访问URL搜索部分,但是如何设置URL(不更改状态和重新加载页面)?
这对我有用:
$stateProvider.state("alerts", { url: "/alerts/list?{query:json}" });
Run Code Online (Sandbox Code Playgroud)
和
$state.go($state.current, {query: {a:1, b:2, c: '3'}}, {location: true, inherit:true, notify:false})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9567 次 |
| 最近记录: |