我的所有事件发射器都正常工作,除了一个.
child.ts:
@Component({
...
outputs: ['fileUploaded']
})
export class childComponent implements OnInit {
...
fileUploaded = new EventEmitter<boolean>();
...
randomMethod(){
...
this.fileUploaded.emit(true);
}
}
Run Code Online (Sandbox Code Playgroud)
从父组件调用randomMethod(),我将在parent.ts中显示.它不是在child.html中调用的.
parent.html
...
<child (fileUploaded)="onSubmit($event)"></child>
..
Run Code Online (Sandbox Code Playgroud)
parent.ts
export class parentComponent {
...
theChild = new childComponent;
submitted = false;
...
onSubmit(event: boolean) {
console.log('in onSubmit()');
this.submitted = event;
}
functionCallsChild(){
this.theChild.randomMethod();
...
this.theChild = new childComponent;
}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序从不记录"在onSubmit()"中,为什么不调用此方法?我也尝试不在我的最后一行创建一个新的子对象,但这没有什么区别.