title: Keep reference of ViewChild in parent class
body: <p>I want to access to my graph in my child component through @ViewChild, which is declared in my parent class. I don't want to redeclare a new variable for every child class.</p>
  
  <p>Parent class:</p>
  
  <pre><code>import { Component, ViewChild} from '@angular/core';
  import { BaseChartDirective } from 'ng2-charts';
  import { LabelOptions } from '../labelOptions';
  
  @Component({
    selector: 'app-graph',
    styleUrls: ['./graph.component.css']
  })
  export class GraphComponent {
  
    @ViewChild(BaseChartDirective) public chart: BaseChartDirective;
    //[.....some properties of a Graph.....]
  
    public setChart(data: any[], labels: string[]){
        this.chart.labels = labels;
        this.chart.datasets = data;
        this.update();
    }
  
  }
  </code></pre>
  
  <p>Child class: </p>
  
  <pre><code>import { Component, OnInit } from '@angular/core';
  import { GraphComponent } from '../../../shared/graph/graph.component';
  
  @Component({
    selector: 'app-pie-graph',
    templateUrl: './pie-graph.component.html',
    styleUrls: ['./pie-graph.component.css']
  })
  export class PieGraphComponent extends GraphComponent implements OnInit {
  
    constructor(){
      super();
      this.setType("pie");
    }
  
    public chartHovered(e:any): void {
      console.log(e);
    }
  
    ngOnInit(){
      this.setType("pie");
      console.log(this.chart);
      this.setChart([234, 234, 234], ["a", "b", "c"]);
      //console.log(this.chart);
    }
  }
  </code></pre>
  
  <p>The problem occurs when I try to access to the parent class' methods, it throws me undefined, in my case the problem is with <code>setChart</code></p>