AngularJS UI router: How to configure nested named views?

后端 未结 1 1423
后悔当初
后悔当初 2020-12-24 02:30

I have a configuration like below:

...
.state(\'profiles\', {
    abstract: true
    , url : \'/profiles\'
    , resolve: {...}    
    , views: {
      main         


        
相关标签:
1条回答
  • 2020-12-24 03:08

    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

    0 讨论(0)
提交回复
热议问题