How can I use ViewChild to call a method in a different component?
I have a method in the piechart component that I want to access from the app component using ViewChild.
In my piechart.component.ts file:
export class PiechartComponent {
constructor() { }
pie(){
console.log("Hello World")
}
}
In my app.component.ts file:
export class AppComponent {
@ViewChild(PiechartComponent) piechart:PiechartComponent;
constructor(){ }
pieChart(){
this.piechart.pie();
}
}
In my app.component.html file:
<button (click)="pieChart()">Pie Chart</button>
After clicking the button, I should see the output "Hello world". However, I am encountering the following error: "TypeError: Cannot read property 'pie' of undefined"