4
        <grid
            [data]="sortedDeviceList"
            [multiSelect]="false"
            [enableSort]="true"
            [rowTemplate]="">
        </grid>

I want to pass a HTML template to the rowTemplate property. And the template will look like this.

<div> 
 <div>{{item.id}}</div>
 <div>{{item.name}}</div>
</div>

The grid template look likes this.

<div *ngFor="let item in data">
// template should appear here.
</div>

How to do this?

Anuradha Gunasekara
  • 6,553
  • 2
  • 27
  • 37

1 Answers1

10
@Component({
  selector: 'grid'
  template: `
<div *ngFor="let item in data" *ngForTemplate="templateRef" *ngOutletContext="{$implicit: data}">
</div>`
})
export class GridComponent {
  @Input() data:any[];
  constructor(private templateRef:TemplateRef) {}
}

and use it like

<template #myTemplate>
  <div> 
   <div>{{item.id}}</div>
   <div>{{item.name}}</div>
  </div>
</template

See also

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567