以上述相同的情況下,我不希望這使每個父 - 我的>子組件實現OnInit
界面和使用的生命週期掛鉤方法ngOnInit()
調用componentHandler.upgradeAllRegistered();
。從我的源代碼示例: 儀表板式的組件(父)
@Component({
templateUrl : './app/dash/dashboard.html',
directives : [ROUTER_DIRECTIVES,MenuComponent],
Encapsulation : ViewEncapsulation.NONE
})
export class DashBoard implements OnInit{
userFullname : string;
imagePath : string;
constructor(private _router : Router){}
ngOnInit() {
this.imagePath = 'app/dash/avatar.png';
componentHandler.upgradeAllRegistered();
this.userFullname = localStorage.getItem('user');
}
}
然後菜單組件(子)
@Component({
selector : 'menu-pane',
templateUrl : './app/dash/menu/menu.html',
providers : [HTTP_PROVIDERS,MenuService],
directives : [ROUTER_DIRECTIVES]
})
export class MenuComponent implements OnInit{
routesReady : boolean;
routerView : any[];
constructor(private menuServ : MenuService, private _router : Router){}
ngOnInit(){
componentHandler.upgradeAllRegistered();
this.routerView = [];
}
}
我猜的片段是有點混亂搞清楚,但你可以簡單地在每個組件的ngOnInit()中調用方法
我同意!但是,Material2仍處於第一個開端,目前還沒有這樣的基本組件。我期待着Material2變得像Material1一樣豐富。 –