0
我有父和子组件,从子需要触发父组件功能。输出事件发射器触发只在ngOnInit
Parent.component.ts
loadData(event) {
console.log(event);
}
Parent.component.html
<app-project (uploaded)="loadData($event)" ></app-project>
child.component.ts
@Output() uploaded:EventEmitter<any> = new EventEmitter();
ngOnInit() {
this.uploaded.emit('complete'); // Worked
}
loadProject(){
this.uploaded.emit('complete'); // Not triggering the parent function
}
child.component.html
<button type="button" (click)="loadProject(project)" label="Load Project"></button>
不知道什么是错在这一点,但是从ngOnInit workes。
从child.component.html调用loadProject。
从哪里调用loadProject()? –
有一个函数(editProject)在child.component.ts从那里调用 editProject(project:Project){ this.uploaded.emit('complete'); } –
也许编辑你的问题是一个更好的主意,因为评论中的代码很难阅读。还请在调用'editProject()'的地方添加信息。 –