0
私は次のHTML持っ角度アプリケーションで親にクラスを追加する方法はありますか?
// This is parent
<div class="some-class">
// This is child
<totalizer</totalizer>
</div>
どのように私は、子供から親スタイル(新しいクラスを追加)を変更できますか?
私は次のHTML持っ角度アプリケーションで親にクラスを追加する方法はありますか?
// This is parent
<div class="some-class">
// This is child
<totalizer</totalizer>
</div>
どのように私は、子供から親スタイル(新しいクラスを追加)を変更できますか?
あなたは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>
これを修正します
詳細はngClass
here。