angular - 由于类型为“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
解决方案
你可以和
*ngIf="rejectStatus"
如果为 1,则条件为真,否则为假。也不需要在函数中返回相同的值。您只需要设置变量的值。
推荐阅读
- reactjs - 如何从列表中只选择一项?
- flutter - 在颤动中格式化按钮和嵌套ListView
- clearcase - 明文格式字符串中的新行
- c++ - 即使使用 ##__VA_ARGS__ 也无法编译零参数的可变参数宏
- wordpress - 如何在 WPBakery 中创建 vc_col-sm-5 和 vc_col-sm-7 自定义布局?
- python - 无法以日期为索引绘制 MACD
- c# - CS0411 方法 xyz 的类型参数无法从用法中推断出来
- shopify - 当单击立即购买按钮时,我想在 Shopify 产品页面中设置注释属性
- php - 在 Laravel 中,如何为中间件中的所有输入过滤 reuqest 对象上的字符串?
- google-oauth - 尝试在 Google API 中为访问令牌交换授权码时出现“redirect_uri_mismatch”错误