Angular2 checkbox checked or not
I am using angular 2 with stuff. I want to check the box for the material if you check the box. I did by passing the click event to the component function. But when using material the checkbox doesn't work. It only works when using html checkbox.
<md-checkbox class="example-radio-button" [value]="hobby 1" (click)="hobbyClicked($event)">
hobby 1
</md-checkbox>
hobbyClicked(evt){
console.log(evt.target.checked); // undefined
}
+3
source to share
1 answer
Use a directive [ngModel]
and (change)
, based on the checked box or not, you can get the value from the DOM.
<md-checkbox class="example-radio-button"
[ngModel]="hobby" value="hoby 1"
(change)="hobbyClicked($event)">
hobby 1
</md-checkbox>
code
hobbyClicked(evt){
console.log(evt.checked ? evt.source.value: ''); // undefined
}
+1
source to share