2017-05-15 11 views
1

私のアプリケーションにはカードコンポーネントがあります。どのタイプのカードに基づいているのかは、テンプレートのルート要素に適用する必要がある別のスタイルです。角度 - コンポーネントのルート要素にクラスを適用しないセレクタ

<card class="card-type-class"></card> 

私のHTMLはこのように見える終わる:

<card class="card-type-class"> 
    <div class="other-constant-classes"> 
     content of my card 
    </div> 
</card> 

の代わりに、このような:

<card> 
    <div class="other-constant-classes card-type-class"> 
     content of my card 
    </div> 
</card> 

は、セレクタからクラスを適用するためにとにかくがあり、私はこれを行うとコンポーネントテンプレートのルート要素?

***申し訳ありませんが、これはあなたが常に文字列としてクラスに渡すことができます...私はその質問を検索する方法を考え出す苦労していた、

+0

属性ベースセレクタは機能しますか? 'セレクタ: '[tn-labelfor]'、'使用法 '

+0

https: /angular.io/docs/ts/latest/guide/attribute-directives.html –

答えて

1

を依頼されている場合:

<card [myClass]="'card-type-class'"></card> 

そして、下のコンポーネントで:

@Input() myClass: string; 

そしてHTML:

<div class="other-constant-classes {{myClass}}"> 
    content of my card 
</div> 
関連する問題