【发布时间】:2018-06-01 14:11:36
【问题描述】:
我需要过滤一个选择的数据,因为有太多的选项。 我是这样做的:
<mat-form-field>
<mat-select placeholder="Unit.." (change)="onTabChange(element, $event.value.id, 'assignedUnit')">
<input matInput type="text" (keyup)="filterListCareUnit($event.target.value)">
<mat-option *ngFor="let careUnit of listCareUnits" [value]="careUnit">
{{ careUnit.label }}
</mat-option>
</mat-select>
</mat-form-field>
一键启动,我打电话给filterListCareUnit($event.target.value)
但是在这个函数中我不知道要使用过滤器 rxjs
我有我的listCareUnits,我想删除所有不包含$event.target.value 的对象
现在我这样做了,但显然不起作用,我的列表总是包含相同的项目:
filterListCareUnit(val) {
console.log(val);
this.listCareUnits.filter((unit) => unit.label.indexOf(val));
}
angular/rxjs 的新手 .. 感谢您的帮助
【问题讨论】:
-
您没有在该代码中使用 rxjs。 material2 在内部使用它。无论如何,您的问题很可能是您没有将过滤后的列表分配回您的 listCareUnits var:
this.listCareUnits = this.listCareUnits.filter((unit) => unit.label.indexOf(val) > -1);
标签: angular typescript rxjs