我知道有关于这个主题的问题,我看了一下文档,但我无法理解如何使用输出。
这个@Output有一个子组件
//here I define the Ouput on the child component
@Output() turvo: EventEmitter<boolean> = new EventEmitter();
//here I emit the event on the child component
ngOnInit() {
this.turvo.emit(false);
}
父组件
//here I listen to the emitted event on the parent
<div (turvo)="atribuirTurvoDoFilho($event)"></div>
//here is the function that should be executed on the parent.
public atribuirTurvoDoFilho(data) {
console.log("I will never execute :(");
this.turvo = data;
}
我没有错误,但没有沟通。
如果您想要一个可行的解决方案,请分享您的完整子组件。
现在,我可以看到,您尝试在div元素上运行输出 - 这是一个html标记,而不是角度组件。
如果定义输出,则它仅适用于定义的组件。