src/pipes/alias-board-name/alias-board-name.ts
Name | aliased |
Pure | true |
transform | ||||||
transform(val: string)
|
||||||
Parameters :
Returns :
string
|
Private Static cachedAliases |
Type : literal type[]
|
import {Pipe, PipeTransform} from '@angular/core';
import {FormAndFrameworkUtilService} from '@app/services';
@Pipe({
name: 'aliased',
pure: true
})
export class AliasBoardName implements PipeTransform {
private static cachedAliases: { name: string, code: string, alias: string }[];
constructor(
private formAndFrameworkUtilService: FormAndFrameworkUtilService
) {
if (AliasBoardName.cachedAliases) {
return;
}
this.formAndFrameworkUtilService.getBoardAliasName().then((fields) => {
AliasBoardName.cachedAliases = fields;
});
}
transform(val: string): string {
if (!AliasBoardName.cachedAliases) {
return val;
}
const alias = AliasBoardName.cachedAliases.find(a => a.name === val);
if (alias) {
return alias.alias;
}
return val;
}
}