How to call a function received from async stream using Angular async pipe? Error: Cannot have a pipe in an action expression

How to call a function received from async stream using Angular async pipe? Error: Cannot have a pipe in an action expression

我想使用 Angular 9 异步管道调用从数据流接收的函数。

以下代码 (onApprove)="(modalData$ | async).onApprove()" 抛出此错误:Cannot have a pipe in an action expression

网上没找到解决方法,只能参考ngModel的问题()

<div class="confirm-modal-container">
  <div class="title">{{(modalData$ | async).title}}</div>
  <div class="body">{{(modalData$ | async).body}}</div>
    <app-action-buttons (onApprove)="(modalData$ | async).onApprove()" (onCancel)="(modalData$ | async).onCancel()" [cancelText]="currentStep === 0 ? 'Cancel' : 'Previous'" [approveText]="control[currentStep].actionBtnText"></app-action-buttons>
</div>

数据流来自Redux store

@select((state: IAppState) => state.ui.modal.modalData) readonly modalData$: Observable<any>;

您可以在 ng-container 分组元素中提取响应并在所有较低的嵌套级别使用响应。这样您甚至不需要每次都调用 async

<div class="confirm-modal-container">
    <ng-container *ngIf="modalData$ | async as modelData">
        <div class="title">{{modelData.title}}</div>
        <div class="body">{{modelData.body}}</div>
        <app-action-buttons (onApprove)="modelData.onApprove()" (onCancel)="modelData.onCancel()" [cancelText]="currentStep === 0 ? 'Cancel' : 'Previous'" [approveText]="control[currentStep].actionBtnText"></app-action-buttons>
    </ng-container>
</div>