简体   繁体   中英

Angular 2 load component using 'selector' dynamically

I am facing an issue in angular 2 for load component based on ' selector ' name.

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.

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.

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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