2

I want to use pipe using a variable, in this case i have a columns object with pipe key that will use in the template. How can i achieve that?

columns = [
    {
        key: 'Amount',
        name: 'Amount',
        width: 'col-xs-1',
        pipe: "number:'1.2-2'"
    },
    {
        key: 'TransactionDate',
        name: 'Transaction Date',
        width: 'col-xs-1',
        pipe: "date:'medium'"
    }
];

transactions = [
   {
    "TransactionDate": "2018-04-27T14:55:30.2",
    "Amount": 5,
   }
];

I tried to use column.pipe in the template iteration but i'm getting template parse error

<tr *ngFor="let transaction of transactions; let counter = index">
    <td *ngFor="let column of columns" class="{{ column.width }}">{{ transaction[column.key] | column.pipe }}</td>
</tr>

Any suggestion? Thanks in advance!

Juan
  • 429
  • 3
  • 6
  • 19
  • 1
    check this https://stackoverflow.com/questions/43788650/using-pipe-name-as-a-variable-in-the-template-in-angular2 – Niladri May 08 '18 at 08:10

0 Answers0