-
Notifications
You must be signed in to change notification settings - Fork 0
/
table-col.pipe.ts
37 lines (31 loc) 路 916 Bytes
/
table-col.pipe.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Pipe, PipeTransform, Injector } from "@angular/core";
/**
* A table column pipe for formatting different values
*/
@Pipe({ name: 'tablecol' })
export class TableColPipe implements PipeTransform {
/**
* Creates an instance of TableColPipe.
* @param {Injector} injector The app injector
*/
constructor(private injector: Injector) {
}
/**
* Format the value with the given pipe
*
* @param {*} value The value to format
* @param {PipeTransform} pipe The pipe to use
*/
transform(value: any, pipe: PipeTransform): any {
if (pipe) {
try {
pipe = this.injector.get(pipe);
if (pipe && pipe.transform)
return pipe.transform(value);
} catch (ex) {
console.error("Cannot use pipe => ", pipe, ex);
}
}
return value;
}
}