あなたは、ダイナミックなスタイリングのためのコンポーネントとngClass間の通信のためのサービスを使用することができます。
notification.service.ts
import {Injectable, EventEmitter} from '@angular/core';
@Injectable()
export class NotificationService {
private static _emitters: { [ID: string]: EventEmitter<any> } = {};
static get(ID: string): EventEmitter<any> {
if (!this._emitters[ID]) {
this._emitters[ID] = new EventEmitter();
}
return this._emitters[ID];
}
}
コンポーネントの実行がメッセージを送信する兄弟。
bar.component.ts
import { NotificationService } from 'notification.service';
....
ngOnInit() {
NotificationService.get('barcomponent').emit(true);
}
ngOnDestroy() {
NotificationService.get('barcomponent').emit(false);
}
...
は、あなたのコンポーネントから受信したメッセージに耳を傾けます。
foo.component.ts
import { NotificationService } from 'notification.service';
....
ngOnInit() {
NotificationService.get('barcomponent').subscribe(value => {
this.activateStyle = value;
});
}
....
あなたはhttp://stackoverflow.com/questions/のngClass
foo.component.html
....
<div [ngClass]="{'my-css-class':activateStyle}">
...
</div>
....
DEP経由で任意のクラスを適用することができます36527605/how-to-style-child-components-from-parent-components-css-file – micronyks
私は親からのものであり、兄弟からではないその投稿を読んでいます。 –
あなたはお尻を作りたいですか? – micronyks