Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  87] [ 7]  / answers: 1 / hits: 18055  / 10 Years ago, sun, may 11, 2014, 12:00:00

I have a configuration like below:



...
.state('profiles', {
abstract: true
, url : '/profiles'
, resolve: {...}
, views: {
mainModule: {
templateUrl : '/partials/home.html'
, controller : 'HomeCtrl'
}
, leftSidePaneModule: {
templateUrl : '/partials/leftSidePane.html'
, controller : 'LeftSidePaneCtrl'
}
}
})
...


Main Jade File



...
.col-xs-4.col-md-4.chat_block(ui-view='leftSidePaneModule', autoscroll=false)
...


So, leftSidePaneModule module gets populated in to ui-view='leftSidePaneModule' placeholder. But the problem is, I have 2 more named views inside leftSidePaneModule template. leftSidePaneModule template looks like this:



leftSidePaneModule.html



<div>
<div ui-view=leftWidgetOne></div>
<div ui-view=leftWidgetTwo></div>
</div>


How do i make modules leftWidgetOne & leftWidgetOne gets populated in to above placeholder?



I tried,



...
.state('profiles', {
abstract: true
, url : '/profiles'
, resolve: {...}
, views: {
mainModule: {
templateUrl : '/partials/home.html'
, controller : 'HomeCtrl'
}
, leftSidePaneModule: {
templateUrl : '/partials/leftSidePane.html'
, controller : 'LeftSidePaneCtrl'
}
, 'leftWidgetOne@leftSidePaneModule' : {...}
, 'leftWidgetTwo@leftSidePaneModule' : {...}
}
})
...


Attempt: 2



...
.state('profiles', {
abstract: true
, url : '/profiles'
, resolve: {...}
, views: {
mainModule: {
templateUrl : '/partials/home.html'
, controller : 'HomeCtrl'
}
, leftSidePaneModule: {
templateUrl : '/partials/leftSidePane.html'
, controller : 'LeftSidePaneCtrl'
, views: {
'leftWidgetOne' : {...}
, 'leftWidgetTwo' : {...}
}
}
}
})
...


Both are not working.



How do you do it?



Thanks!


More From » angularjs

 Answers
33

The solution could be found here: View Names - Relative vs. Absolute Names. A cite:




Behind the scenes, every view gets assigned an absolute name that follows a scheme of viewname@statename, where viewname is the name used in the view directive and state name is the state's absolute name, e.g. contact.item

...

(note: in our case it must be 'profiles').




The point is, that we can use the full (absolute) name of the view, being part of the current state definition:



$stateProvider
.state('profiles', {
url: '/profiles',
views: {
mainModule: {
template: '<div>' +
' <h1>Main</h1>' +
' <div ui-view=leftSidePaneModule></div>' +
'</div>',
},
// here we do target the view just added above, as a 'mainModule'
// as <div ui-view=leftSidePaneModule>
'leftSidePaneModule@profiles': {
template: '<div>' +
' <div ui-view=leftWidgetOne></div>' +
' <div ui-view=leftWidgetTwo></div>' +
'</div>',
},
// and here we do target the sub view
// but still part of the state 'profiles' defined in the above
// view defintion 'leftSidePaneModule@profiles'
'leftWidgetOne@profiles': {
template: '<h2>One</2>',
},
'leftWidgetTwo@profiles': {
template: '<h2>Two</2>',
},
}
});


There is also plunker showing the above code in action


[#71086] Friday, May 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dantel

Total Points: 7
Total Questions: 102
Total Answers: 97

Location: Saint Lucia
Member since Sat, Jun 6, 2020
4 Years ago
dantel questions
;