I'm trying to build a dynamic table where i wand to decide in run time which pipe to use (If Any).
I'm trying to achieve something similar to (Simplified):
export class CellModel {
public content: any;
public pipe: string
}
Table
<tbody>
<tr *ngFor="let row of data">
<template ngFor let-cell [ngForOf]=row>
<td *ngIf="cell.pipe">{{cell.content | cell.pipe}}</td>
<td *ngIf="!cell.pipe">{{cell.content}}</td>
</tr>
</tbody>
I understand that this example gives an error. Can i use Reflect is some manner or some other solution?
You can't apply pipes dynamically. What you can do is to build a "meta" pipe that decides what transformation(s) to do.
and then use it like
For runtime compile only you can create a directive which will compile template dynamically.
UPDATE:
Using
compileModuleAndAllComponentsAsync
for RC.6^dynamic-pipe.ts
Plunker sample RC.6^
OBSOLETE SOLUTION
In RC.5 you can use
Compiler.compileComponentSync/Async
to do that:dynamic-pipe.ts
And use it this way:
See also the plunker sample RC.5 that demonstrates this feature.
Anyway i think Günter's solution is preferable