由网友(嘟嘟鱼)分享简介:我有这条路线 \r\r .STATE('mystate',{\r 网址:'/ {ID}\r templateUrl:/views/partial.html\r}); \r\r\r的ID参数应该在这样的2a542f61-5fff-4607-845d-972e6c3ad1e4形式一个GUID。我如何在URL...
我有这条路线
rr
.STATE('mystate',{r 网址:'/ {ID}r templateUrl:/views/partial.htmlr});
rrr
的ID参数应该在这样的2a542f61-5fff-4607-845d-972e6c3ad1e4形式一个GUID。我如何在URL中添加此URL:/ {ID:?我应该怎么把这里}'。
解决方案您可以定义自己的类型参数。
VAR GUID_REGEXP = / ^ [AF D] {8} - ([AF D] {4} - ){3} [AF D] {12} $ /一世;$ urlMatcherFactoryProvider.type('的GUID',{ EN code:angular.identity, 德code:angular.identity, 是:函数(项目){ 返回GUID_REGEXP.test(项目); }});
下面是一个展示上plunker这种解决方案
然后指定这种类型的URL路径前pression:
.STATE('mystate',{ 网址:'/ {GUID的id?}', templateUrl:/views/partial.html});
您可以了解更多关于在文档的页面
I have this route
.state('mystate', {
url: '/{id}',
templateUrl: '/views/partial.html'
});
The id param should be a guid in form like this "2a542f61-5fff-4607-845d-972e6c3ad1e4". How do i add this in the url "url: '/{id:?what should i put here}'".
解决方案You can define your own type of parameter.
var GUID_REGEXP = /^[a-fd]{8}-([a-fd]{4}-){3}[a-fd]{12}$/i;
$urlMatcherFactoryProvider.type('guid', {
encode: angular.identity,
decode: angular.identity,
is: function(item) {
return GUID_REGEXP.test(item);
}
});
Here is a showcase on plunker with this solution
Then specify this type in url route expression:
.state('mystate', {
url: '/{id?guid}',
templateUrl: '/views/partial.html'
});
You can read more on that page in docs
相关推荐
最新文章