I'm having some trouble targeting nested views on a single page with multiple views. Here's my code.
$stateProvider
.state('root', {
abstract: true,
url: '/',
views: {
'viewA': {
templateUrl: '/views/viewA.html'
},
'viewB': {
templateUrl: '/views/viewB.html'
}
}
})
.state('root.sectionA1', {
url: '',
views: {
'viewASub': {
templateUrl: '/views/viewA.Section1.html'
}
}
})
.state('root.sectionA2', {
url: '',
views: {
'viewASub': {
templateUrl: '/views/viewA.Section2.html'
}
}
})
.state('root.sectionB1', {
url: '',
views: {
'viewBSub': {
templateUrl: '/views/viewB.Section1.html'
}
}
})
.state('root.sectionB2', {
url: '',
views: {
'viewASub': {
templateUrl: '/views/viewB.Section2.html'
}
}
})
My index.html
<body>
<div ui-view="viewA"></div>
<div ui-view="viewB"></div>
</body>
The html to my 2 sections
<!-- viewA.html -->
view A content
<div ui-view="viewASub"></div>
<!-- viewB.html -->
view B content
<div ui-view="viewBSub"></div>
At this point all the subview states for viewA show up fine. I'm able to add multiple sections and show different states using the ui-sref link. But I'm unable get any of the 'viewB' subviews so show up. When I place the 'root.sectionB1' above 'root.sectionA1' the second section subviews show up fine. I'm assuming that I need to be more specific in how I'm referencing the parent of each subview. I'm I missing something here?
You have had a copy / paste mistake in
root.sectionB2
the view should beviewBSub
then I think it's working as expected.Please have a look at the demo below or at this fiddle.