There is an updated and working plunker with boolean
custom type
In case, we would like to work with a bool like type, which
expects and accepts the:
true
, false
, 0
, 1
we just have to register our custom type:
app.config(['$urlMatcherFactoryProvider', function($urlMatcherFactory) {
$urlMatcherFactory.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/
})
}]);
And then we can use this url defintion inside of any state:
...
, url: '/foo/{isBar:boolean}'
...
NOTE: why boolean
? not bool
? Because bool
is already registered for 0|1
as far as I remember
Check it here
ORIGINAL
simple solution working with "strings" in this updated plunker,
... // states definitions
, url: '/foo/{isBar:(?:bool|true|0|1)}'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…