【发布时间】:2020-12-18 22:06:19
【问题描述】:
我有通过 component.ts 从 .json 文件中获取的表格数据:
import lfirawdata from '../../../assets/json/data.json';
interface lfiexport {
id: string;
sgm: string;
pl: string;
qr: string;
}
export class lfiComponent implements OnInit{
lfilist: lfiexport [] = lfirawdata;
然后,我在组件中使用 html 将其显示在表格中:
<tr *ngFor="let lfiexport of lfilist">
<td>{{lfiexport.id}}</td>
etc.
我想在表格顶部添加一个选择菜单,一旦您选择了值,表格将只显示那些具有该选定值的行。
<mat-form-field>
<mat-select placeholder="Single City" name="city">
<mat-option *ngFor="let sgm of sgms" [value]="sgm.value">
{{ sgm.viewValue }}
</mat-option>
</mat-select>
</mat-form-field>
我尝试使用
谢谢
【问题讨论】:
-
我相信对你来说最好的解决方案是 ngFor 已经过过滤列表