angularjs - How define url params inside state common for each child state -
this config:
.state('index.oz', { abstract: true, url: '/oz', views: { 'mainview@': { templateurl: "views/oz/oz.html", controller: 'ozcontroller' } } }) .state('index.iz.a', { url: '/a/:id', params: { id: { value: null, squash:true } }, views: { 'oztypeview': { templateurl: "views/oz/a.html", controller: "ozacontroller" } } }) .state('index.oz.b', { url: '/b/:id', params: { id: { value: null, squash:true } }, views: { 'oztypeview': { templateurl: "views/oz/ozb.html", controller: 'ozbcontroller' } } }); my desired urls are:
/oz/a
/oz/b
/oz/a/45
/oz/b/12
how can make url in each child state don't have in each state write following piece fo code:
params: { id: { value: null, squash:true } } more spedific, can somehow put piece of code inside parent abstract state, or maybe define parameter id inside parent state, keeping desired urls mentioned above? basicly, i'll have couple child states , don't want each state repeat same params code.
i guess directly cant, can reduce code duplication this:
function statewithid(name, cfg) { cfg.url += '/:id'; if (!cfg.params) { cfg.params = {}; } cfg.params.id = { value: null, squash:true }; $stateprovider.state(name, cfg); } statewithid('index.iz.a', { url: '/a', views: { 'oztypeview': { templateurl: "views/oz/a.html", controller: "ozacontroller" } } }); statewithid('index.iz.b', { url: '/b' });
Comments
Post a Comment