我有一个动态组件,需要在事件处理程序函数中获取引用。我无法使用,ViewChild
因为这些组件是动态的,并且在模板内部等。
<example #e (click)="onExample(e)" />
当我做以上e
是undefined
。如何从处理程序中获取对组件本身(而不是元素)的引用?
对于投射的内容,可以使用ContentChild代替ViewChild,也许适合您的情况-请参阅文档:https ://angular.io/api/core/ContentChild 。
这是一篇关于该主题的好文章:https : //blog.mgechev.com/2016/01/23/angular2-viewchildren-contentchildren-difference-viewproviders/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句