I seem to be encountering a persistent error:
"ERROR TypeError: Cannot set property 'checked' of undefined"
Take a look at my code snippet from test.component.ts:
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatSlideToggle } from '@angular/material/slide-toggle';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements OnInit {
@ViewChild('testSlider', { static: false }) t: MatSlideToggle;
constructor() { }
ngOnInit() {
this.t.checked = true;
}
}
Additionally, here's the relevant part from test.component.html
<mat-slide-toggle #testSlider>Test</mat-slide-toggle>
I can't quite figure out what I'm missing here. Any insights would be greatly appreciated!