[英]ngx-smart-modal - How to interact with component from class reference?
When I open a modal using a class reference via...当我使用 class 参考打开模态时...
// component
this.ngxSmartModalService.create('myModal2', MyComponent).open();
How can I interact with that component?我如何与该组件交互? How can I provide a value to an @Input or call a method on the component?
如何为 @Input 提供值或调用组件上的方法? Basically, any examples or tutorials on how to meaningfully interact with the component will be greatly appreciated.
基本上,任何关于如何与组件进行有意义交互的示例或教程都将不胜感激。
To pass from input variables to a component created in your typescript, you can do so with the ResolverFactory component and the instance entry.要将输入变量传递给在 typescript 中创建的组件,您可以使用 ResolverFactory 组件和实例条目来执行此操作。
Assuming that your component has a data
input:假设您的组件有
data
输入:
const componentFactory = this.componentFactoryResolver.resolveComponentFactory(adItem.component);
const componentRef = viewContainerRef.createComponent(componentFactory);
(<AdComponent>componentRef.instance).data = adItem.data;
More details on documentation有关文档的更多详细信息
Actually dynamic components with template bindings couldn't be rendered properly.实际上,带有模板绑定的动态组件无法正确呈现。 It seems it's a limitation for many libraries.
这似乎是许多图书馆的限制。 I created an issue about this topic in order to fix it as soon as possible.
我创建了一个关于这个主题的问题,以便尽快修复它。
Someone did a great fix and we will try to release it really soon.有人做了一个很好的修复,我们会尽快发布它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.