[英]Angular - using how to call function on component created dynamically using ng-dynamic-component
I am using the npm package ng-dynamic-component to create dynamic components. 我正在使用npm包ng-dynamic-component创建动态组件。
I am in a situation where i want to call a specific function on the dynamically created component using this package. 我处于一种情况下,我想使用此程序包在动态创建的组件上调用特定函数。
I have experimented with a lot of different ways but so far found no solution. 我已经尝试了许多不同的方法,但是到目前为止没有找到解决方案。
Does anyone have any idea if it is possible to call a function on a component that is created dynamically using the mentioned package? 有没有人知道是否可以在使用上述包动态创建的组件上调用函数?
Thanks :) 谢谢 :)
ng-dynamic-component has a "Component Creation Event" ndcDynamicCreated
that passes a ComponentRef<any>
as a parameter. ng-dynamic-component具有“组件创建事件”
ndcDynamicCreated
,该事件将ComponentRef<any>
作为参数传递。
From the docs: 从文档:
@Component({
selector: 'my-component',
template: `<ndc-dynamic [ndcDynamicComponent]="component"
(ndcDynamicCreated)="componentCreated($event)"
></ndc-dynamic>`
})
class MyComponent {
component = MyDynamicComponent1;
componentCreated(compRef: ComponentRef<any>) {
// utilize compRef in some way ...
}
}
Utilizing compRef in some way would be calling a function of the compRef.instance
property in your case. 以某种方式使用compRef将在您的情况下调用
compRef.instance
属性的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.