去这里的方法是按照习惯type.
如图所示问答 https://stackoverflow.com/a/27182177/1679310,如果我们想创建某种准备好处理值的类型true, false, 1, 0 as boolean
,我们可以这样定义它(有也正在工作 http://plnkr.co/edit/w5fHQbaFU4VaXkTxyBGq?p=preview):
app.config(['$urlMatcherFactoryProvider', function($urlMatcherFactoryProvider) {
$urlMatcherFactoryProvider.type('boolean',
// our type custom type
{
name : 'boolean',
decode: function(val) { return val == true ? true : val == "true" ? true : false },
encode: function(val) { return val ? 1 : 0; },
equals: function(a, b) { return this.is(a) && a === b; },
is: function(val) { return [true,false,0,1].indexOf(val) >= 0 },
pattern: /bool|true|0|1/
})
}]);
我们可以用同样的方式定义我们的类型
$urlMatcherFactoryProvider.type('state' , ...
$urlMatcherFactoryProvider.type('city' , ...
$urlMatcherFactoryProvider.type('category', ...
稍后我们可以将它们用于任意数量的状态定义:
...
.state('mystate', {
url: 'xxx/{state:state}/{city:city/{category:category}
...
这一切都可以工作,因为我们可以定义 url网址匹配器 http://angular-ui.github.io/ui-router/site/#/api/ui.router.util.type:UrlMatcher像这样
'{' name ':' regexp|type '}'
- 带有正则表达式或类型名称的卷曲占位符。如果正则表达式本身包含大括号,它们必须成对出现或用反斜杠转义。
所以,不仅是正则表达式,还有type
- 包括我们定制的