2017-09-15 10 views

答えて

3

あなたはngClassを使用して動的にcssクラスを追加/削除する親コンポーネントに信号をEventEmitter@Output()プロパティを使用することができます。あなたの子供で

totalizerコンポーネント、定義、

@Output() cssRefresh = new EventEmitter<boolean>(); 

//when you need to add/remove css emit an event out to the parent like this 
// (preferably in a method in this component), 

this.cssRefresh.emit(true); // or 'false' depending on add/remove 

はその後、親htmlに、このメソッドとプロパティを追加し、

addCss = false; // set 'initial state' based on your needs 

refreshCss(add: boolean) { 
this.addCss = add ? true : false; 
} 
をあなたの親コンポーネント内部

<div class="some-class" [ngClass]="{ 'dynamicClass1 dynamicClass2 dynamicClass3': addCss}"> 
    // This is child 
    <totalizer (cssRefresh)=refreshCss($event)></totalizer> 
</div> 

これを修正します

詳細はngClasshere

関連する問題