2017-07-11 5 views

答えて

5

これは非常に基本的なもので、https://angular.ioのガイドでたくさんの例が見つかります。

まだ見つからない場合は、@Outputデコレータを使用し、EventEmitterフィールドを設定し、ボタンをクリックするとemitを呼び出す必要があります。あなたはイベント表記()を使用して、あなたの親からそれに接続することができますこの方法:

@Component({ 
    selector: 'parent', 
    template: `<child (buttonClick)="onButtonClick($event)"></child>` 
}) 
export class ParentComponent { 

    public onButtonClick(event: MouseEvent): void { 
     // ... 
    } 

} 

@Component({ 
    selector: 'child', 
    template: `<button (click)="buttonClick.emit($event)"></button>` 
}) 
export class ChildComponent { 

    @Output() 
    public buttonClick: EventEmitter<MouseEvent> = new EventEmitter<MouseEvent>(); 

} 
関連する問題