无法使用带有火基的 Angular 中的键值对到达内部对象



我有一个json对象,它有一个名为data的内部对象,它有data: {count: 9, message: "9 sites synced"} -也是json对象。我试图从message中获取值,而不是从count中。下面是我的模板代码:

<div class="full-width border-radius-4 overflow-hidden">
<!-- Header -->
<div class="head accent p-24 pb-16" fxLayout="column" fxLayoutAlign="space-between">
<div fxLayout="row" fxLayoutAlign="end center">
</div>
</div>
<mat-accordion class="full-width example-headers-align" multi *ngIf="liveActions$ | async as actions; else: loading">
<mat-expansion-panel *ngFor="let action of actions">
<mat-expansion-panel-header *ngIf="action.type == 'single'">
<mat-panel-description fxFlex="30%">
<div class="lgreen material-icons" *ngIf="action.status  == 'completed'">done_all</div>
<div class="red material-icons" *ngIf="action.status == 'pending'">pending_actions</div>
<div class="blue material-icons" *ngIf="action.status == 'queued'">pending</div>
<div class="yellow material-icons" *ngIf="action.status == 'error'">error</div>
</mat-panel-description>
<mat-panel-description fxFlex="40%">{{action.key}}</mat-panel-description>
<div *ngFor="let dataItem of action?.data | keyvalue">{{dataItem?.value?.message}}
</div>
<!--        <mat-panel-description>{{action.startDate | date:'medium'}}</mat-panel-description>-->
</mat-expansion-panel-header>
</div>
</mat-expansion-panel>
</mat-accordion>
<ng-template #loading>Loading&hellip;</ng-template>
</div>

当我执行{{dataItem?.value?我什么也没得到。当我做dataItem。值,我得到计数和消息的值。

我只需要message的值。我做错了什么?

<代码>

withkeyvalue管道,它将转换动作。数组

下面的数据对象
dataItem?.value?.message = undefined
dataItem.value = 9 and 9 sites synced

:

{{ dataItem.key === 'message' ? dataItem.value: ' '}}

这就是你看到的。

你可以在绑定要显示的值时添加一个条件

PP_5还有其他方法…我想你现在可以弄清楚发生了什么,需要按照你的要求做什么。

最新更新