角UI路由器动态查询字符串的定义字符串、路由器、定义、动态

由网友(闻香识女人)分享简介:我们有一个搜索页面,我们有数以千计的,可以通过管理面板定义搜索属性。一个特点搜索结果页面有一个网址像:We have a search page and we have thousands of search attributes that can define by an admin panel. A charac...

我们有一个搜索页面,我们有数以千计的,可以通过管理面板定义搜索属性。一个特点搜索结果页面有一个网址像:

We have a search page and we have thousands of search attributes that can define by an admin panel. A characteristic search result page has a url like that:

http://example.com/search?a12=3213&a314=412412&a247=1941829&....

当我们要使用角UI路由器来实现该页面与AngularJS一个SPA,我不明白,我们怎么可以定义路由配置和我们如何能够读取查询字符串的所有搜索参数。因为 UI路由器的力量来定义路由配置每queryparam可能性在 $ stateParams 来使用它们。

When we want to implement that page as a SPA with AngularJS by using angular-ui-router, I couldn't understand, how can we define that route configuration and how can we read all search parameters from querystring. Because ui-router forces to define every queryparam possibilities on route configuration to use them in $stateParams.

$stateProvider.state('search', {
    url: '/search?a1&a2&a3&a4&a5' // what about a1314?
    controller: function ($stateParams) {
        console.log($stateParams.a1314);
    }
});

你知道解决方法吗?

Do you know a workaround?

推荐答案

您可以使用$ location.search()在网​​址:'/搜索搜索路径的控制器

you can use $location.search() in url: '/search' search route's controller

它当前URL返回搜索部分(如对象)时,不带任何参数调用。

it return search part (as object) of current url when called without any parameter.

var searchObject = $location.search();

// => {a12: '3213', a314: '412412'}

console.log(searchObject .a12); //3213

和路由可以使用

 url: '/search*' 

所以它会匹配

阅读全文

相关推荐

最新文章