I am a bit new to Angular (version 8) and Typescript. I have code where users choose what type of chart, columns, and title to make a Google Chart after a click of a button.
I have tried to put the element in my chart.component.html inside a div with a specific id, and then appending google chart data after it is provided by the users with "innerHTML". I have all the data saved in local variables for type, data, title, etc.
Note: I have correctly imported GoogleChartComponent from 'angular-google-charts', as well as ViewChild from 'angular-core'.
I target the #here div element like this inside my chart.component.ts:
@ViewChild('googleChart', {static: false})
googleChart: GoogleChartComponent;
This is in my chart.component.ts: ...
@Component({
...
})
export class ChartComponent implements OnInit {
...
createChart(){
this.here.nativeElement.innerHTML = "<google-chart [title]='title' [type]='type' [data]='data' [columnNames]='googleColumnNames' [options]='options' [width]='width' [height]='height'> </google-chart>";
}
...
}
And this is in my chart.component.html:
<button type="submit" id="chartButton" class="btn" (click)="createChart()">
Create Chart
</button>
<div #here class="chartCreator"></div>
In the inspector, I see that the element has been appended inside the #here div element, but nothing is displayed and its width and height are shown as 0x0.