I'm facing the next error while trying to follow ngx-datatable demo and using Angular 12.
I have installed the npm package, I alredady have imported the module in the app.module.ts, but using the demo code I have the next error.
1- While declaring ViewChild reference I get the next error
2- Derived from the previous error I cannot assign values to my object properties
What I did: I added ? to my object, the first error was solved but the second one was not.
Does anyone know how to solve it?
This is de code I am using: TemplateRef via Column Property
My code until now
import { RestService } from './../services/rest.service';
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { ColumnMode } from '@swimlane/ngx-datatable';
import { RestService } from '../services/rest.service';
@Component({
selector: 'app-list-views',
templateUrl: './list-views.component.html',
styleUrls: ['./list-views.component.css'],
})
export class ListViewsComponent implements OnInit {
@ViewChild('editTmpl', { static: true }) editTmpl: TemplateRef<any>;
@ViewChild('hdrTpl', { static: true }) hdrTpl: TemplateRef<any>;
rows = [];
columns = [];
ColumnMode = ColumnMode;
constructor(private service: RestService) {}
ngOnInit() {
this.columns = [
{
cellTemplate: this.editTmpl,
headerTemplate: this.hdrTpl,
name: 'Title',
},
{
cellTemplate: this.editTmpl,
headerTemplate: this.hdrTpl,
name: 'Views',
},
{
cellTemplate: this.editTmpl,
headerTemplate: this.hdrTpl,
name: 'Image',
},
];
}
fetch() {
this.service.get('myUrl').subscribe((res: any) => (this.rows = res));
}
}