首页 > 解决方案 > 从类型 T 更改为类型 Observable在角

问题描述

我正在尝试在我的应用程序中使用 ngrx 商店和效果。到目前为止,我一直使用“车辆”类型:

export class Vehicle {
  name: string;
  id: number;
  alarm: Alarms[];
}

我使用了一项服务从我的 web api 获取数据。我后来用它来创建我的车辆清单。现在我想使用 NGRX,为此我需要使用类型

Observable<Vehicle[]> 

我的 HTML 代码如下所示:

 <!-- list of vehicles -->
        <aside class="vehiclelist">
            <mat-nav-list matSort (matSortChange)="sortData($event)">
                <th mat-sort-header="timestamp">Latest alarm</th>
                <th mat-sort-header="status">Status</th>
                <mat-list-item *ngFor="let stuff of sortedVehicles" class="vehicles">
                    <span [ngClass]="getColors(stuff)">
                    </span>
                    <p matLine (click)="updateInfo(stuff.id)"> {{ stuff.name }} </p>
                    <button mat-icon-button id="btn" *ngIf='check(stuff.alarm)' matTooltip="{{stuff.alarm[tooltipIndex(stuff)]?.timestamp}} - {{stuff.alarm[tooltipIndex(stuff)]?.description}}">
                        <mat-icon>info</mat-icon>
                    </button>
                </mat-list-item>
            </mat-nav-list>
        </aside>

现在我把我的 ngFor 改成了这样:

<mat-list-item *ngFor="let stuff of (vehicles$ | async)" class="vehicles">

这一切都很好,但我不能再在我的函数参数中使用我的“东西”。有什么我可以做的,以便我可以在我的(点击)功能中使用“东西”吗?

标签: angulartypescriptrxjsngrx

解决方案


推荐阅读