I have a Template Driven Form in which i am putting a checkbox that can toggle its value.
Component
public toggles = [
{ value: 'toggled', display: 'Toggled' },
{ value: 'untoggled', display: 'UnToggled' },
];
<div>
<input type="hidden" name="toggle" [(ngModel)]="user.toggle">
<div>
<label>
<input type="checkbox"
[checked]="user.toggle === toggles[0].value"
(change)="$event.target.checked? (user.toggle = toggles[0].value) : (user.toggle = toggles[1].value)">
{{ toggles[0].display }}
</label>
</div>
</div>
The following works great, but when i am switching to Angular Material it just fails to works .
The material Template code
<input type="hidden" name="toggle" [(ngModel)]="user.toggle">
<md-checkbox [checked]="user.toggle === toggles[0].value"
(change)="$event.target.checked?(user.toggle = toggles[0].value): (user.toggle = toggles[1].value)">
{{toggles[0].display}}</md-checkbox>
I am getting the following Error in console, it says cannot read the property of undefined console,
TypeError: Cannot read property 'checked' of undefined
at Object.eval [as handleEvent] (TemplateDrivenComponent.html:64)
I know the point where the error is occurring $event.target.checked angular cannot read this checked event on md-checkbox , how to get around this any pointers will be great
thanks
this?