0

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.

enter image description here

1- While declaring ViewChild reference I get the next error

Property not initialized

2- Derived from the previous error I cannot assign values to my object properties

TemplateRef not assignable

What I did: I added ? to my object, the first error was solved but the second one was not.

enter image description here

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));
  }
}
  • Does this answer your question? [Property '…' has no initializer and is not definitely assigned in the constructor](https://stackoverflow.com/q/49699067/8017690) – Yong Shun Aug 25 '21 at 23:51
  • Does this answer your question? [What is “not assignable to parameter of type never” error in typescript?](https://stackoverflow.com/q/52423842/8017690) – Yong Shun Aug 25 '21 at 23:53

0 Answers0