ui-router icon indicating copy to clipboard operation
ui-router copied to clipboard

NG2: Abstract named view regression

Open dissoupov opened this issue 9 years ago • 2 comments

I'm migrating from UI-Router Angular 1.5 to Angular 2, and the root abstract state is not working as it's used to be.

I have a root named UIView, let's call it (main@), and AppMainPage component that defines nested views for Toolbar, Nav, Content, etc.

@Component({
selector: 'app',
styles: [],
template: `
<div ui-view="main" class="tw-view tw-column"> 
   <div layout="column" layout-align="center center"> 
        <div>loading ui-view...</div> 
    </div> 
</div>
`
})

Registration:

UIRouterModule.forRoot({
  states: [
    {
      name: 'app',
      abstract: true,
      views : {
       'main@': AppMainPage,
       'toolbar@app': AppToolbar,
       'navigation@app': AppNavigation,
       'quickPanel@app': AppQuickPanel
       }
    },

The AppMainPage is never initialized if I provide {views} option.

The same approach is working with UI-Router for Angular 1.5:

$stateProvider
      .state('app', {
        abstract: true,
        views   : {
          'main@' : {
            template: '<app-main-page class="tw-page-content row"></app-main-page>'
          },
          'toolbar@app'   : {
            template: '<app-toolbar></app-toolbar>',
          },
          'navigation@app': {
            template: '<app-navigation></app-navigation>',
          },
           'quickPanel@app': {
             template: '<app-quick-panel class="app-quick-panel"></app-quick-panel>',
           }
        }
      })
    ;

Please advise if it's supported in NG2 module.

dissoupov avatar Jan 18 '17 16:01 dissoupov

UPDATE: The docs seems to be misleading:

// Named views shorthand: // Inside a "views:" block, a Component class (NavBar) is shorthand for { component: NavBar }

Actually this does not work. 'main@': AppMainPage,

If I replace the statement with explicit 'component' option 'main@': { component: AppMainPage }, then abstract named views work great!

dissoupov avatar Jan 18 '17 17:01 dissoupov

Oh, really sorry about that. I updated the docs before updating the code.

Track this issue: https://github.com/ui-router/ng2/issues/19

christopherthielen avatar Jan 19 '17 02:01 christopherthielen