Angular 异步管道减少流值而不是显示最新排放

Angular async pipe reduces stream value rather than displays latest emission

我对 mergeMap 的使用似乎将布尔流减少为一个值,因为

<button [disabled]="!(canRequestPricing$ | async)"

canRequestPricing$ | async应该是真的,但是如果第一次发射是假的,那就是假的。

public canRequestPricing$ = new BehaviorSubject<boolean>(false);


public ngOnInit(): void {
    this.canRequestPricingSubscription = this.canRequestPricing$.pipe(
        mergeMap(() => this.mappedItem.canRequestPricing()),
        take(1),
        mergeMap((canRequestPricingFromApi) => {
            const can = this.canRequestPricing() && canRequestPricingFromApi;
            return of(can);
        })).subscribe();
}

由于发射器初始化为 false,因此 (canRequestPricing$ | async) 等于 false。当我用 true 初始化它时, (canRequestPricing$ | async) 等于 true.

const can = this.canRequestPricing() && canRequestPricingFromApi; 始终为真,这是正确的,我只需要 public canRequestPricing$ = new BehaviorSubject<boolean>(false); 的首字母 false 不影响最终值。

我希望行为是 (canRequestPricing$ | async) 相当于上次排放量。我如何获得这种行为?

如果我理解正确,canRequestPricing$ 依赖于 this.canRequestPricing()this.mappedItem.canRequestPricing()

this.mappedItem.canRequestPricing().pipe(
  take(1),
  map(canRequestPricingFromApi => this.canRequestPricing() && canRequestPricingFromApi)
).subscribe(can => {
  this.canRequestPrincing$.next(can);
})