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()'的地方添加信息。 –