0

I have the following JSON:

columns: [{
    id: 'id',
    header: 'Employee ID',
    value: 'id',
    hasPipe: false
  },
  {
    id: 'name',
    header: 'Employee Name',
    value: 'name',
    hasPipe: true,
    pipe: 'customPipe'
  },
  {
    id: 'address',
    header: 'Employee address',
    value: 'address',
    hasPipe: false
  },
]

In the HTML file, I have the following code:

<ng-container *ngFor="let eachCol of Columns" matColumnDef="{{eachCol.id}}">
      <th mat-header-cell *matHeaderCellDef mat-sort-header>{{eachCol.header}}</th>
      <td mat-cell *matCellDef="let row">
        {{ eachCol.hasPipe ? (row[eachCol.value] | eachCol.pipe) : (row[eachCol.value]) }}
      </td>
</ng-container>

I have referred following answer https://stackoverflow.com/a/36937308/7100922 I get template parse errors.

F_V
  • 125
  • 1
  • 11
  • You are sure that error is cause because of the pipe?, what happen if you test like without the pipe? something like this `{{ eachCol.hasPipe ? (row[eachCol.value] + ' | ' + eachCol.pipe) : (row[eachCol.value]) }}`. – cabesuon Jan 27 '20 at 18:54
  • 2
    You cannot use a dynamic pipe like that. I suppose you can use a master pipe and pass in the pipe name through there, and choose from within that pipe which pipe should be used for the transform – Poul Kruijt Jan 27 '20 at 19:04
  • I tried using dynamic pipe... have followed https://stackoverflow.com/a/46910713/7100922, now I'm getting StaticInjectorError(Platform: core)[customPipe]: NullInjectorError: No provider for customPipe!g error. Have declared customPipe in the providers array. – F_V Jan 28 '20 at 08:02

0 Answers0