我试图从孩子的输出传递到其父,引发 不知道为什么它只是将无法正常工作,角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