material icon indicating copy to clipboard operation
material copied to clipboard

feat(radio-group): support ng-model-options trackBy

Open GustavSt opened this issue 9 years ago • 7 comments

similar to #2862 md-radio-group doesn't set value to be selected if it is using objects and using a pre set value. plunkr to illustrate it doesn't work.

For md-select this was fixed by setting ng-model-options="{trackBy: '$value.id'}" It would be nice if md-radio-group had something similar. Or is it possible to achieve the same behavior?

GustavSt avatar Dec 10 '15 16:12 GustavSt

+1 @ThomasBurleson why is this labeled with Deprecated ?

alextobies avatar Apr 22 '16 10:04 alextobies

You have to put ng-model and ng-model-options on the <md-radio-button> element. It will work correctly if you do this.

bsandrow avatar May 20 '16 18:05 bsandrow

@GustavSt I've been struggling with this. Using ng-click as a workaround (plunkr), but it has obvious limitations.

jonuts avatar Jun 02 '16 19:06 jonuts

I have exactly the same problem. We switched the core software to angular material and now we need object model support on the md-radio-button. Selecting is fine, but we cannot make the form initialize with the radio button set based on the model property. I tried using ng-class="{'md-checked':EXPRESSION}" but it immediately gets overridden moments after applying the md-checked. I am at a loss at how to acheive this functionality in angular material. bsandrow's suggestion did not work.

jklappstein avatar Nov 25 '16 00:11 jklappstein

@bsandrow - md-radio-button does not support ng-model. Can you post working sample?

zendu avatar Mar 07 '18 06:03 zendu

I verified that this is still not supported in 1.1.8 by using this updated Plunker.

I can see how this could be helpful as the use cases described above are clear and may be commonly encountered. This is also a standard feature of AngularJS that would be nice to support.

I am reopening this as we would welcome a contribution from the community to add ng-model-options support to md-radio-group.

Splaktar avatar Mar 26 '18 06:03 Splaktar

Workaround: find the matching value in the options, and assign that to the ng-model: https://codepen.io/jakobadam/pen/rvjRRg?editors=1010

jakobadam avatar Apr 30 '18 13:04 jakobadam