首页 > 解决方案 > 由于类型为“Promise”,此条件将始终返回“false”' 和 '1' 没有重叠

问题描述

我正在尝试将标签从“pending”或“pendiente”更改为“pendient-rejected”或“pendiente-rechazado”。听起来像是一个简单的改变,这不是我想要做的。

这是我用来获取每一行日志的函数。

  async getLogs(formId: string) {
    (await this.supervisorService.getLogs(formId)).subscribe((logs) => {
      console.log("historic length: "+logs.length);
      console.log("onelog: "+logs[0].ID_ESTADO);
      console.log("logs: "+logs.length);
      this.rejectStatus=0;
      for(var i=0; i < logs.length; i++){
        if(logs[i].ID_ESTADO==1227){
          this.rejectStatus=1;
        }
      }      
    });
    return this.rejectStatus;
  }

这就是我试图在 html 中应用它的方式:

<ng-container matColumnDef="lastLog">
  <th mat-header-cell *matHeaderCellDef>Estado</th>
  <td mat-cell *matCellDef="let row">
    <div *ngIf="getLogs(row.ID_FORM) === 1 ; else elseBlock">
      {{row?.lastLog?.ID_ESTADO}}
      Pendiente-Rechazado
    </div>
    <ng-template #elseBlock>
      <app-state [state]="row?.lastLog?.ID_ESTADO"></app-state>
    </ng-template>        
  </td>
</ng-container>

但我收到错误:

错误 TS2367:此条件将始终返回 'false',因为类型 'Promise' 和 '1' 没有重叠。

我能做什么,因为我读到的解决方案不适用于 HTML。

在这里您可以找到这两个文件: https ://stackblitz.com/edit/angular-ivy-t5dfrq?file=src/app/forms-table/forms-table.component.html

标签: angular

解决方案


你可以和 *ngIf="rejectStatus"

如果为 1,则条件为真,否则为假。也不需要在函数中返回相同的值。您只需要设置变量的值。


推荐阅读