I have an ion-segment that will display different graphs (using Chart.js) when selected:
<div [ngSwitch]="segment">
<canvas *ngSwitchCase="'bpmGraph'" #bpmChart></canvas>
<canvas *ngSwitchCase="'stepGraph'" #stepChart></canvas>
</div>
<div padding>
<ion-segment [(ngModel)]="segment">
<ion-segment-button (click)="retrieve()" value="bpmGraph">
BPM
</ion-segment-button>
<ion-segment-button (click)="retrieve()" value="stepGraph">
Steps
</ion-segment-button>
</ion-segment>
</div>
And I am grabbing the elements using @ViewChild:
segment: string = "bpmGraph"; // initial segment is bpm
@ViewChild('bpmChart') bpmCanvas: ElementRef;
@ViewChild('stepChart') stepCanvas: ElementRef;
Then later on graphing with the nativeElement:
let ctx = this.bpmCanvas.nativeElement.getContext("2d");
let bpmChart = new chart(ctx, {...});
The issue is that @ViewChild will only grab the initially selected canvas (in this case bpmCanvas) and all others will be null, as they are not selected by the segment. How can I get references to all canvas elements?