【发布时间】:2019-07-19 19:32:50
【问题描述】:
我有一个步进器,它由单个 observable 调节
<ng-container *ngIf="!(categoriesLoading$ | async); else loading">
<mat-vertical-stepper *ngIf="categories$ | async as categories">
<mat-step>
<categories-form [categories]="categories"></categories-form>
</mat-step>
</mat-vertical-stepper>
</ng-container>
现在我想添加另一个 observable qualifications$ 的条件
类似的东西:
<ng-container *ngIf="!(categoriesLoading$ | async); else loading">
<mat-vertical-stepper *ngIf="categories$ | async as categories">
<mat-step>
<categories-form [categories]="categories"></categories-form>
</mat-step>
<mat-step>
<qualifications-form [qualifications]="qualifications"></qualifications-form>
</mat-step>
</mat-vertical-stepper>
</ng-container>
在控制器中:
categories$: Observable<Array<Category>>;
categoriesLoading$: Observable<boolean>;
qualifications$: Observable<Array<Qualification>>;
qualificationsLoading$: Observable<boolean>;
我怎样才能正确地做到这一点?
【问题讨论】:
-
这样的? - 我不太确定您的意思:
*ngIf="!(categoriesLoading$ | async) && (qualificationsLoading$ | async); else loading"您是否希望扩展第 1 行的条件?或扩展第 2 行的 for 循环? (第二个例子) -
@JonasPraem 我想通过添加
qualifications$observable 来获得与第一个示例相同的结果 -
我会重新考虑它的设计......你可能会遇到竞争条件。我会用 .pipe() 链接这些 observables,然后等待最后一个解决并根据最终结果采取行动,而不是同时处理 2 个。
标签: javascript angular typescript rxjs ngrx