angularjs - What are the benefits of returning a function in templateURL? -
angularjs - What are the benefits of returning a function in templateURL? -
from https://github.com/angular-ui/ui-router/wiki
templateurl can function returns url. takes 1 preset parameter, stateparams, not injected.
$stateprovider.state('contacts', { templateurl: function ($stateparams){ homecoming '/partials/contacts.' + $stateparams.filterby + '.html'; } })
what of benefits of returning function in templateurl? sorry if bit vague. i'm trying wrap head around ui-router.
a "benefit" perhaps unusual way set it. adds way router dynamically decide template utilize given route, depending on $stateparams
. alternative way of achieving similar utilize ngif
s or ngswitch
s in single template route.
which 1 utilize think own preference / think coding practice task in hand. if have 2 radically different, , long, templates, utilize function dynamic template url. if had short, or similar, templates, utilize ngif
.
also, i've used ui-router few times now, , far never used function templateurl
.
angularjs angular-ui-router
Comments
Post a Comment