Zysce
Zysce

Reputation: 1240

Angular2 - Dynamically add selector in template

I would like to dynamically build selector or call component in the template with a property. Like in this plunker.

Example :

<!-- What I want to do -->
<frame-{{type}}></frame-{{type}}>

<!-- Or -->
<frame [type]="{{type}}"></frame>

Is there a workaround for this or is it not possible with angular2 ?

Upvotes: 3

Views: 1849

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657731

That's at least currently not supported. Components and directives are only applied to static HTML.

You can use DynamicComponentLoader ViewContainerRef.createComponent to imperatively add/remove comonents.

Upvotes: 2

Related Questions