Components: md-checkbox don't honor the [value] binding

Created on 7 Jun 2017  路  6Comments  路  Source: angular/components

Bug, feature request, or proposal:

md-checkbox don't honor the [value] binding.

What is the expected behavior?

https://material.angular.io/components/component/checkbox mentions an @Input value property that can be set as the value for this input.

What is the current behavior?

It only uses boolean values, it does not use whatever the user specifies in [value].

What are the steps to reproduce?

http://plnkr.co/edit/4ryXsamVJlcMaDHJsEgu?p=preview

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: https://goo.gl/DlHd6U

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

When trying to implement a checkbox-list control I want to have an array with the values that are represented by the checkboxes.

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

Angular material: 2.0.0-beta.6
Angular: 4.1.1

Is there anything else we should know?

P5 materiacheckbox feature help wanted

All 6 comments

@lobo-tuerto you can get the value in the (change) event, ie. (change)="doSomething($event.source.value)"
See this http://plnkr.co/edit/uEcocFj4q7EUUxebjQff?p=preview

@macjohnny Thanks for the useful example.

So do you think it's currently behaving as expected or should it be different?

@lobo-tuerto I think this is currently behaving as expected. It is the behavior of ngModel, and not related to material / md-checkbox, since the input binding for the value exists.

Maybe the confusion (or frustration) comes from the fact that the component has two different conteptual things that look similar at a first glance: it's state (true/false) and it's value. The state is what's (correctly) passed to ngModel.

But this aproach is not so useful when you have a list of checkboxes to check (in this case, @macjohnny 's example plunker is a good way to handle it).

Take a look at this issue: #4926. Someone is asking for implementation of a MdCheckboxGroup feature. If it gets implemented, it'll possibly work like MdRadioGroup, binding the value property of the selected checkboxes to ngModel of the MdCheckboxGroup.

I think this is a bug, not a feature. if you submit a HTML form with <input type="checkbox" name="foo" value="bar"> the parameter foo will have the str value bar, not bool true.

I agree with masterfloda, I'm trying to set a value in a reactive form on a mat-checkbox element via the [value]="some angular variable" attribute. All I get out of the form is true or null. I would expect to get the specified value or null since that's what a regular checkbox would give me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3mp3ri0r picture 3mp3ri0r  路  3Comments

RoxKilly picture RoxKilly  路  3Comments

theunreal picture theunreal  路  3Comments

Miiekeee picture Miiekeee  路  3Comments

jelbourn picture jelbourn  路  3Comments