Consider such scenario of a state with query parameters. I'd like to have them declared as flags so I can fetch then in the controller and get true
, false
or undefined
$stateProvider.state('foo.bar', {
url: '/foobar?flag1&flag2',
templateUrl: 'foo/bar/template.tpl.html',
controller: 'FooBarCtrl'
});
myModule.controller('FooBarCtrl', function($stateParams){
$stateParams.flag1 <<--- is string but can it be of type bool?
$stateParams.flag2 <<--- is string but can it be of type bool?
});
Some URL examples:
/foobar?flag1=true -->> should yield {flag1: true, flag2: undefined}
/foobar?flag2=false -->> should yield {flag1: undefined, flag2: false}
/foobar?flag1=false&flag2=true -->> should yield {flag1: false, flag2: true}
/foobar?flag1=1&flag2=0 -->> should yield {flag1: true, flag2: false}
etc...
At the moment $stateParams delivers only strings. Is there away to make the router to parse the params as flags? That would be much more elegant than doing the parsing manually in the controller.