【发布时间】:2020-04-27 09:15:24
【问题描述】:
我有 2 个检查特定条件的函数,我希望它们都为真。 在这种情况下,您将如何使用 *ngIf?目前,如果我设置其中一个它可以工作,但我需要它们两个。
HTML
<p *ngIf="(isFree$ | async) && (order$ | async)">Free Plan</p>
TS
public order(data) {
const order = data.externalOrderId;
if (order.substring(0, 4) === 'asdad') {
return true;
} else {
return false;
}
}
public isFree$ = this.planType$.pipe(
map((data) => {
return (data.plan === 'Free');
}
));
【问题讨论】:
-
不,我看到了这个;所以我需要条件为真......我如何在 ngIf 中使用 and
-
无法理解!
-
合并 observables 并使用
map运算符将它们编组为布尔值。 -
@TheHeadRush 怎么样?
-
这真的取决于你正在组合的可观察对象。您可能应该查看learnrxjs.io/operators/combination,看看哪个运算符最适合您的用例。
标签: javascript html angular pipe