大佬教程收集整理的这篇文章主要介绍了Angular 4 – 从子组件调用父方法不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
child.ts:
@Component({ ... outputs: ['fileUploaded'] }) export class childComponent implements OnInit { ... fileUploaded = new EventEmitter<Boolean>(); ... randomMethod(){ ... this.fileUploaded.emit(true); } }
从我将要显示的父组件中调用randomMethod()
parent.ts.它不是在child.html中调用的.
parent.html
... <child (fileUploaded)="onSubmit($event)"></child> ..
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; } }
我的应用程序从不记录“在onSubmit()”中,为什么不调用此方法?我也尝试不在我的最后一行创建一个新的子对象,但这并没有什么区别.
parent.html:
<child #theChild (fileUploaded)="onSubmit($event)"></child>
parent.ts:
export class parentComponent { ... @ViewChild('theChild') theChild; submitted = false; ... onSubmit(event: Boolean) { console.log('in onSubmit()'); this.submitted = event; } functionCallsChild(){ this.theChild.randomMethod(); ... } }
以上是大佬教程为你收集整理的Angular 4 – 从子组件调用父方法不起作用全部内容,希望文章能够帮你解决Angular 4 – 从子组件调用父方法不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。