2

當我們導航到的路線和負載部件,傳遞@input和訂閱@Output而導航到路由在角2組分

  1. 我們可以通過變量與@Input在加載子組件的裝飾,我們可以訂閱EventEmitter@Output裝飾?
  2. Parent是否有任何lifecycle Hook可用,其中Route是定義的,我們可能會獲得對已加載組件的引用,以便動態地將值\ subscribe函數傳遞給子組件。

父組件

@Component({ 
    moduleId: module.id, 
    selector: "parent", 
    templateUrl: "<router-outlet></router-outlet>" 
    }) 
    @Routes([ 
    { path: "/child-component1", component: Child1Component } 
    ]) 
    export class Parent { 
    // Can we pass var1 and subscribe close here of Child1Component when route is navigated dynamically based upon path? 
    // Is there any lifecycleHook available in parent where Route is defined? 
    } 

輔元件

@Component({ 
    moduleId: module.id, 
    selector: "child-component1", 
    template: "<div>{{var1}}</div><button (click)='closeMenu()'>Close</button>" 
    }) 
    export class Child1Component { 
    @Input() var1: string; 
    @Output() close: EventEmitter<any> = new EventEmitter<any>(); 

    constructor() { } 

    closeMenu =(): void => { 
     this.close.emit(""); 
    } 
} 

我使用提前Angular2 RC1

謝謝!

回答