2016-08-04 4 views
1

にスイッチタイプのセットアップなしで、条件付きディレクティブを使用することが可能です私は現在、私が何をしたいのですがどのようながangular2

<div *ngFor="let directive in listOfDirectives"> 
    <directive-one *ngIf="directive == 'directive-one'"></directive-one> 
    <directive-two *ngIf="directive == 'directive-two'"></directive-two> 
    ... 
</div> 

ような何かをやっている、それは

を動作しませんが、このです
<{{directive}} *ngFor="let directive = listofDirectives"></{{directive}}> 

これを行う方法はありますか?スタイリングの目的のために、私は本当に

答えて

2

何かサポートされていません

<{{directive}} *ngFor="let directive = listofDirectives"></{{directive}}> 

のようにdiv要素でラップされないようにする必要があります。

テンプレートに静的に追加されたHTMLのみが、コンポーネントとディレクティブのセレクタと照合されます。

ViewContainerRef.createComponentを使用して追加することができます。具体的には、Angular 2 dynamic tabs with user-click chosen components