我正在使用查询系统,允许用户从动态字段列表构建查询,我想在URL中持久查询.
通常我会这样做:
$stateProvider.state('alerts',{ url: '/alerts/list?p1&p2&p3' })
在控制器中我可以用$stateParam读取params:
console.log($stateParams.p1)
我可以在URL中保存查询:
$state.go($state.current,{p1:'1',p2: '2'},{location: true,inherit:true,notify:false})
但问题是我不能宣布所有的参数.
我想要做:
$state.go($state.current,p2: '2',p3:'3',p4: '4',p5:'5'},notify:false})
但是ui-router忽略了没有声明状态的params.
解决方法
这对我有用:
$stateProvider.state("alerts",{ url: "/alerts/list?{query:json}" });
和
$state.go($state.current,{query: {a:1,b:2,c: '3'}},notify:false})