Components: md-checkbox not behaving correctly (not unchecking on first click)

Created on 1 Dec 2016  路  4Comments  路  Source: angular/components

Bug, feature request, or proposal:

Bug

What is the expected behavior?

When using native checkboxes with Angular2-Data-Table I can toggle columns on or off the table.
When trying to implement md-checkbox the first click doesn't work - the checkbox remains checked.
After the first click the checked value is opposite to the model, i.e. opposite to the native checkboxes.

I tried many ways to fix this but without luck. this seems to be a bug in md-checkbox.

see plunker :
https://plnkr.co/edit/HGUjy5

What is the current behavior?

The first click should toggle the checkbox correctly.

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://plnkr.co/edit/HGUjy5

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.1.2
latest Angular 2 Material

P2

Most helpful comment

You also need to change (click)="toggle(col)" in template to (change)=toggle(col). The (change) event in MdCheckbox will toggle the checkbox again.

All 4 comments

@tinayuangao can you reproduce this?

This is not a bug in md-checkbox. Your isChecked(col) needs to return a boolean to make it work - now it returns {name: ColName}.

The correct isChecked(col) function should be isColChecked(col:any) { return this.columns.find(c => { return c.name === col.name; }) != undefined; }

You also need to change (click)="toggle(col)" in template to (change)=toggle(col). The (change) event in MdCheckbox will toggle the checkbox again.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RoxKilly picture RoxKilly  路  3Comments

jelbourn picture jelbourn  路  3Comments

xtianus79 picture xtianus79  路  3Comments

savaryt picture savaryt  路  3Comments

constantinlucian picture constantinlucian  路  3Comments