The method of using template to reference variables in ts file

  • description:
    angular6 "s UI suite
    uses a third-party UI library table component in the html file, and establishes a template reference variable for it:
    < p-table-sharpdt >

    . This table component has a method exportCSV () that can export the number of
    in the table as CSV. The original official example of
  • is to directly export data in the html file by calling the template reference variable method, without writing any code in the ts
    file, but now I can"t use the same official method for many reasons. Instead, I want to export the data in the
    ts file by calling the template reference variable method, so how should I write it?
  • I am angular novice, if the problem is too simple, please recommend an article, materials to see, if a little difficult
    hope to get some code for reference, thank you very much for your reply.
  • if necessary:
    my Q: 409223171 . If necessary, you can add me as a friend, or send this Q email address directly
  • .
Sep.23,2021

ViewChild

import { Component, ViewChild, AfterViewInit } from '@angular/core';

//table
import { TableComponent } from 'PrimeNG'

@Component({
    selector: 'app-xxx',
    templateUrl: './xxx.component.html',
    styleUrls: ['./xxx.component.css']
})
export class XXXComponent implements AfterViewInit {

    //
    @ViewChild('dt') dt:TableComponent

    constructor() {}

    ngAfterViewInit(){
        //
        this.dt.exportCSV()
    }
}
Menu