我有这个简单的服务:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable()
export class HighlightsService {
private _highlitTab: string = '';
highlitTab$: BehaviorSubject<string> = new BehaviorSubject(this._highlitTab);
public get tab(): string {
return this._highlitTab;
}
public set tab(val: string) {
this._highlitTab = val;
this.highlitTab$.next(this._highlitTab);
}
}
在我的标签中设置:
(select)="highlightsService.tab = 'show component0'
现在在我看来显示多个指令,我如何有条件地显示它们?
<app-component0 [hide]="highlightsService.highlitTab$ | async"></app-component0>
<app-component1 [show]="highlightsService.highlitTab$ | async"></app-component0>
显然这是行不通的,因为没有===
. 有没有ngSwitch
等价的?
如何Component
根据BehaviourSubject
值有条件地显示 s?