简体   繁体   English

Angular-使用如何在使用ng-dynamic-component动态创建的组件上调用函数

[英]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.

相关问题 使用ng-style将动态创建的CSS应用于组件 - Applying dynamically created CSS to a component using ng-style 如何将动态创建的组件作为动态创建的组件的 ng-content 传递? - How to pass a dynamically created component as ng-content of a dynamically created component? 在 React 组件的动态脚本中创建的“窗口”DOM 对象上调用函数 - Call function on 'window' DOM object created in dynamic script for a React component &#39;ng build&#39; 后创建的 Angular 组件不可见 - Created Angular component not visible after 'ng build' 对组件类函数的 Angular ng-change 调用不会触发 - Angular ng-change call to a Component Class function not triggering 如何使用变量动态调用组件或服务? - How do I dynamically call a component or service by using variables? 如何验证使用 ng-repeat、ng-show(角度)动态创建的输入 - How to validate inputs dynamically created using ng-repeat, ng-show (angular) 如何在Angular 6中动态选择子组件中的所有元素? - How to select all the elements in dynamically created child component in Angular 6? 如何在Angular2中的模板html上动态创建数组组件? - How to rendered dynamically created array component on template html in Angular2? 如何使用 querySelector 多次调用相同的角度组件 - How to call the same angular component multiple times using querySelector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM