我将使用管道过滤一些 json 并根据值显示名称
这是我的 JSON
bankAccountUsage = [
{ value: 1, name: "x" },
{ value: 2, name: "y" },
{ value: 3, name: "z" }
];
这是管道:
import { Pipe, PipeTransform } from '@angular/core';
import { StaticValuesService } from '../../services/static-values.service';
import { } from '../../services/static-values.service';
@Pipe({
name: 'accountUsageType'
})
export class AccountUsageTypePipe implements PipeTransform {
private Accounusages;
transform(value: number, args?: any): any {
this.Accounusages.filter(val => {
if (val.value === value) {
console.log(val);
return val.name;
}
});
}
constructor(private _statcvalues: StaticValuesService) {
this.Accounusages = this._statcvalues.bankAccountUsage;
}
}
这是 Console.log(val) 的结果
Object {value: 1, name: "x"}
HTML:
<td>{{account.AccountType | accountUsageType}}</td>
但结果是空的
谢谢