import { Component, TemplateRef, ViewChild } from '@angular/core';
@Component({
selector: 'template-ref-demo',
template: `
TemplateRef via Column Property
Source
Fancy: {{column.name}} !!
`
})
export class TemplateRefTemplatesComponent {
@ViewChild('editTmpl') editTmpl: TemplateRef;
@ViewChild('hdrTpl') hdrTpl: TemplateRef;
rows = [];
columns = [];
constructor() {
this.fetch((data) => {
this.rows = data.splice(0, 5);
});
}
ngOnInit() {
this.columns = [{
cellTemplate: this.editTmpl,
headerTemplate: this.hdrTpl,
name: 'Gender'
}];
}
fetch(cb) {
const req = new XMLHttpRequest();
req.open('GET', `assets/data/company.json`);
req.onload = () => {
cb(JSON.parse(req.response));
};
req.send();
}
}