ngAfterViewInit不起作用

时间:2017-08-24 09:30:42

标签: angular

//Notes Module

////////////
const notesRoutes: Routes = [
  {
    path: 'notes',
    component: NotesComponent,
    children: [{
      path: 'detail',
      component: NotesDetailComponent
    }, {
      path: '',
      redirectTo: 'page1',
      pathMatch: 'full'
    }]
  }
];
//////////////
import { Component, OnInit, ViewChild} from '@angular/core';
...
export class NotesComponent{
  ngAfterViewInit() {
    console.log('NOTES.location ', window.location);
  }
}
///////////////
import { Component, OnInit, ViewChild} from '@angular/core';
...
export class NotesDetailComponent{
  ngAfterViewInit() {
    console.log('DETAIL.location ', window.location);
  }
}
/////////////
//NotesDetail html: <a routerLink="/notes" routerLinkActive="active">Notes</a>
//Notes html: <a routerLink="/detail" routerLinkActive="active">Detail</a>

当我访问routerLink =“/ detail我可以看到console:DETAIL.location但是当我访问routerLink =”/ notes“时我看不到控制台:NOTES.location ...为什么? 请帮忙

也许理由出现在我的父模块中:

@NgModule({
          imports: [
            BrowserModule,
            HomeModule,
            NotesModule,
            NgbModule,
            RouterModule.forRoot([
              {
                path         : '',
                loadChildren : './home/home.module#HomeModule'}, {
                path         : 'notes',
                loadChildren : './notes/notes.module#NotesModule'}
            ])
          ],
          providers    : [homeService, AppGlobal],
          declarations : [AppComponent],
          bootstrap    : [AppComponent]
        })

0 个答案:

没有答案