简体   繁体   English

Angular 2负载组件动态使用“选择器”

[英]Angular 2 load component using 'selector' dynamically

I am facing an issue in angular 2 for load component based on ' selector ' name. 我在基于“ 选择器 ”名称的载荷组件的角度2中遇到问题。

I want to render component in my popup dynamically. 我想动态渲染弹出窗口中的组件。 Something like this - Here is the code: 这样的东西-这是代码:

<div>
 <my-selector></my-selector>
</div>

I want to render component inside the div. 我想在div内渲染组件。

Regarding the question and the plunker mentioned in the comments above. 关于上述评论中提到的问题和问题。 To make you selector work, you just have to add the Component in your AppModule like this. 要使选择器正常工作,您只需要像这样在AppModule中添加组件。

declarations: [ App, PopupComponent, DynamicComponent ]

When you have added the component here, you can use the selector as you want in the App template like this: 在此处添加组件后,您可以在App模板中根据需要使用选择器,如下所示:

<button (click)="openPopup()">Launch demo modal</button>
<hr>
<div>
   <my-selector></my-selector>
</div>
<pre>{{closeResult}}</pre>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM