我想按照這個答案,但它太混亂Angular 2 event catching between sibling components同級組件Anguar之間的溝通2
我想調用一個方法子組件1當點擊子組件的東西2
子組件2發出一個名爲trackClick的事件。
父組件:
<div>
<audio-player></audio-player>
<audio-albums></audio-albums>
</div>
輔元件1(音頻播放機)
// Don't know what to do here, want to call this function
trackChanged(track){
console.log("YES!! " + track);
}
輔元件2(音頻 - 相冊)
<li class="track" (click)="playTrack(track)"> </li>
@Output() trackClick = new EventEmitter<any>();
playTrack(track):void{
console.log("calling playTrack from child 2:" + track);
this.trackClick.next([track]);
}
好吧,我很害怕它必須是child2-> parent-> child1,謝謝虐待 –