我試圖從孩子的輸出傳遞到其父,引發 不知道爲什麼它只是將無法正常工作,角4父組件事件偵聽器不會被孩子發出的事件
兒童:
裝飾:
@Component({
selector: 'child',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
@Output() notify: EventEmitter<string> = new EventEmitter<string>();
onClick(){
this.notify.emit('msg from child component');
}
進口:
import { Component, OnInit, EventEmitter, Output } from '@angular/core';
模板:
<button (click)="onClick()"> search </button>
父級:
onNotifyClicked(message: string): void {
this.showMsg = message;
}
模板:
<child (notify)="onNotifyClicked($event)"> </child>
我到其中通知被髮出的狀態(this.notify.emit( 'MSG從搜索組件') ; 運行,沒有錯誤被拋出的發射) ,但我從來沒有在父處理器onNotifyClicked(),
你怎麼知道的?你有沒有在父處理程序中放置一個console.log? – echonax
@echonax我最初使用了斷點,並沒有進入處理程序,在您的評論後我添加了一個console.log,也沒有任何東西 – lironn
您可以包括您的導入嗎?你在哪裏輸入'@輸出'? – echonax