javascript - Angular UI-Router : URL changed but view isn't loaded -
i'm working on ui-router app nested views. defined states this:
$stateprovider .state('parent', { url: "/parent", views: { 'area1': {templateurl : 'parentview.html'}, 'area2' : ... // other areas + template } }) .state('parent.child1', { url: "/child1", views: { 'area1' : {templateurl : 'child1view.html'}, 'area2' : ... // still other areas, not changing } }) .state('parent.child2', { url: "/child2", views: { 'area1' : {templateurl : 'child2view.html'}, 'area2' : ... // still other areas, not changing } })
when using app, have main view divided areas. in 1st area, use specific html file. if click on link, app goes child state using $state.go('mystate')
. @ time, url changed child view isn't loaded in page.
i searched answers in site, , found question 1 seems encounter same problem here : angular router - url changes view not load
do know missed?
sorry bad english
there a working plunker
most index.html contains these targets:
<body> <div ui-view="area1"></div> <div ui-view="area2"></div> ...
so, if both, parent , child target these, need use absolute naming:
.state('parent.child1', { url: "/child1", views: { 'area1@' : {template : '<h2>child 1 area 1 </h2>'}, 'area2@' : {template : '<h2>child 1 area 2</h2>'}, } }) .state('parent.child2', { url: "/child2", views: { 'area1@' : {template : '<h2>child 2 area 1 </h2>'}, 'area2@' : {template : '<h2>child 2 area 2</h2>'}, } })
let's observe doc:
view names - relative vs. absolute names
behind scenes, every view gets assigned absolute name follows scheme of
viewname@statename
, viewname name used in view directive , state name state's absolute name, e.g. contact.item. can choose write view names in absolute syntax.for example, previous example written as:
.state('report',{ views: { 'filters@': { }, 'tabledata@': { }, 'graph@': { } } })
so, our child needs use 1) view target name 2) delimiter @ , 3) state name (in our string empty representing root): 'area1@'
these links, similar $state.go() work now:
<a ui-sref="parent"> <a ui-sref="parent.child1"> <a ui-sref="parent.child2">
check here
Comments
Post a Comment