【发布时间】:2018-08-13 15:39:15
【问题描述】:
我知道有与此主题相关的问题,我查看了文档,但我不明白如何使用输出。
我有一个带有这个@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;
}
我没有出错,但没有发生通信。
【问题讨论】:
-
必须在子组件标签中设置事件处理程序:
<my-child-component (turvo)="..." ></my-child-component>。 -
我用的是router-outlet,有什么问题吗?
-
必须在发出它的组件的组件标签上设置事件处理程序。
-
@DiegoAlves - This post 应该回答您有关使用路由器插座处理事件的问题。
标签: angular typescript