angular ui router - Multiple named views with dynamic routing in angularjs -
edit: here complete code @ plunker. though can not c in execution same code working @ local. gives console error though
it works perfect. due :id
in /news/:id/
, getting jquery/angular errors in console can not tracked anywhere in code
i can not c doing wrong.
edit: solved plunker https://plnkr.co/edit/fwcubggpvdmj3crofryj
first of trying use ui-router
you're including ngroute
script in plunker. change to
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.min.js"></script>
then should work fine!
i suggest few changes...
1. use ui-sref
instead of href
because it's easier define
ui-sref="post({id:1})"
turns href="#/news/1"
if change url day, have change route file, not each href
.
$stateprovider .state('post', { url: "news/:id"
or
$stateprovider .state('post', { url: "archive/:id"
or
$stateprovider .state('post', { url: "whatever/:id"
2. use abstract state
in example it's way better define abstract state holds header, content , footer - it's typical use case.
ui-router abstract states
an abstract state can have child states can not activated itself. 'abstract' state state can't transitioned to. activated implicitly when 1 of descendants activated.
some examples of how might use abstract state are:
to prepend url child state urls. insert template own ui-view(s) child states populate. optionally assign controller template. controller must pair template. additionally, inherit $scope objects down children, understand happens via view hierarchy, not state hierarchy. provide resolved dependencies via resolve use child states. provide inherited custom data via data use child states or event listener. run onenter or onexit function may modify application in someway. combination of above. remember: abstract states still need own children plug into. if using abstract state prepend url, set resolves/data, or run onenter/exit function, you'll additionally need set template: "".
here's plunker
shows how it.
https://plnkr.co/edit/5fvjaelyxdl5mualt5vy?p=preview
hope helps.
Comments
Post a Comment