angular - 从类型 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">
这一切都很好,但我不能再在我的函数参数中使用我的“东西”。有什么我可以做的,以便我可以在我的(点击)功能中使用“东西”吗?
解决方案
推荐阅读
- linux - 如何在 Vim 中进行搜索和替换?
- r - 在两个公共列 R 的匹配值上连接两个数据帧
- c# - 从 appsettings.json 读取 List<(string,string[])>
- google-cloud-platform - 撤销 1 个令牌会撤销相同 OAuth 客户端 ID + 用户同意对的所有令牌
- javascript - mapbox gl js,用线连接点
- python - cx_oracle 禁用来自控制台的语句回显
- javascript - 在 react native (js) 中为 python cli 编写 ui
- .net - 如何为 Blazor Web Assembly 实现缓存清除
- c++ - 使用共享指针来自另一个线程的纯虚拟调用
- flutter - 为什么我看不到 useTextEditingController 值的更新?