angular - 在 ngFor 中使用变量
问题描述
我有很多 ngFor 的表,我如何从 getList() 的项目中做 HTML 中的局部变量?
我需要用户#?
例子:
<div *ngFor="let #item of getList()"></div>
?以及如何在下一个 ngFor HTML 中使用局部变量?
解决方案
我有表格示例:
<div class="card mb-4">
<div class="card-body card-table">
<div class="table-responsive">
<table class="table table-striped table-bordered">
<thead>
<tr>
<th class="align-middle">Przydział:</th>
<th class="align-middle" *ngFor="let distinctStatus of groupByList(list, 'status')">{{distinctStatus.status}}</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let distinctId of groupByList(list, 'id')">
<td class="align-middle">{{distinctId.id}}</td>
<td class="align-middle text-right" *ngFor="let distinctStatus of groupByList(list, 'status')">
<span *ngFor="let value of groupByList(list, 'id', 'status')">
<span *ngIf="value.id == distinctId.id && value.status == distinctStatus.status">{{value.number}}</span>
</span>
</td>
</tr>
<tr>
<td class="align-middle font-weight-bold">Razem:</td>
<td class="align-middle text-right font-weight-bold" *ngFor="let distinctStatus of groupByList(list, 'status')">
<span *ngFor="let value of groupByList(list, 'status')">
<span *ngIf="value.status == distinctStatus.status">{{value.number}}</span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
我如何从 thead tr th 中获取 distinctStatus 变量,因为我需要在 body tr td 中将此变量与 ngIf 一起使用(将 value.property 与 distinct.property 进行比较。现在我有很多 ngFor,因为在 ngFor 范围之后我无法获得 distinctStatus 变量。
推荐阅读
- java - 为什么在通过 OSHI API 从传感器检索信息时会发生这种情况?
- typescript - 如何在 VS Code 上使用 typescript 调试feathersjs?
- reactjs - React 钩子更新多个状态变量
- mysql - SQLSTATE[HY000] [1045] 用户 'qualitym_yaseen'@'localhost' 的访问被拒绝(使用密码:YES)
- angular - 如何获取 mat-table 的当前元素并放入代码的另一部分?
- python - 如何检查参数是否传递给函数?
- angular - TypeScript 构造函数重载无法识别类型
- javascript - 未处理的承诺拒绝警告
- xamarin.forms - Xamarin DatePicker 如何显示星期几?
- excel - 匹配参考数据中的 3+ 列