[英]How can i access ui-router's UrlMatcher?
In the documentation of ui-router
there is a object named UrlMatcher which i need to access it in order to use some methods (such as exec
) but i cannot find any clear instructions on how to do it. 在
ui-router
的文档中,有一个名为UrlMatcher的对象,为了使用某些方法(例如exec
),我需要对其进行访问,但是我找不到有关如何执行此操作的明确说明。 However that object is described on the documentation page. 但是,该对象在文档页面上进行了描述。
I want to be able to do something like: 我希望能够执行以下操作:
new UrlMatcher('/user/{id}?q&r').exec('/user/bob', {
x: '1', q: 'hello'
});
How can i access that object? 如何访问该对象?
Angular has $urlMatcherFactory and UrlMatchers . Angular有$ urlMatcherFactory和UrlMatchers 。
Plunker: http://plnkr.co/edit/MdazdvpVKjZhNjI6ErAH?p=preview 柱塞: http ://plnkr.co/edit/MdazdvpVKjZhNjI6ErAH?p=preview
angular.module('myApp',[]).run(['$urlMatcherFactory',
function($urlMatcherFactory) {
var sourceList= ['John', 'Paul', 'George', 'Ringo']
var names = sourceList.join('|');
var urlMatcher = $urlMatcherFactory.compile("/{source:(?:" + names + ")}/:id");
$stateProviderRef
.state('names', {
url: urlMatcher,
templateUrl: 'tpl.root.html',
controller: 'MyCtrl'
});
}
]);
Refer: Discussion on ui-router's UrlMatcher . 请参阅: 关于ui-router的UrlMatcher的讨论 。
Using exec: 使用exec:
URL: /home/1?param1=tt 网址: / home / 1?param1 = tt
var urlMatcher = $urlMatcherFactory.compile("/home/:id?param1");
var matched = urlMatcher.exec($location.path(), $location.search());
you get 2 fields
: id ==> 1 and param1 ==> tt 您将获得2个
fields
: id ==> 1和param1 ==> tt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.