angular ui router - 只获取查询字符串参数

时间:2017-06-20 15:54:56

标签: angularjs angular-ui-router

想知道是否有内置的方法来获取查询字符串参数而没有额外的路径参数?

来自docs$stateParams的示例:

// If you had a url on your state of:
url: '/users/:id/details/{type}/{repeat:[0-9]+}?from&to'

// Then you navigated your browser to:
'/users/123/details//0'

// Your $stateParams object would be
{ id:'123', type:'', repeat:'0' }

// Then you navigated your browser to:
'/users/123/details/default/0?from=there&to=here'

// Your $stateParams object would be
{ id:'123', type:'default', repeat:'0', from:'there', to:'here' }

我希望在这种情况下与其他人区别开来。

1 个答案:

答案 0 :(得分:1)

来自$location服务的

$location.search()就是这样做的。

docs中的示例:

// given URL http://example.com/#/some/path?foo=bar&baz=xoxo
var searchObject = $location.search();
// => {foo: 'bar', baz: 'xoxo'}