components icon indicating copy to clipboard operation
components copied to clipboard

mat-radio-group data binding does not work when parent component is repeated

Open kwall2004 opened this issue 8 years ago • 9 comments

Bug, feature request, or proposal:

Fix mat-radio-group data binding so it works when parent component is repeated.

What is the expected behavior?

mat-radio-group data binding should work when parent component is repeated.

What is the current behavior?

mat-radio-group data binding does not work when parent component is repeated.

What are the steps to reproduce?

See that both mat-radio-group and the standard html radio inputs are bound to the same property, yet the mat-radio-group data binding only works in the 3rd instance of the parent component.

https://stackblitz.com/edit/angular-gt2qqc

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

I need to be able to repeat the parent component of mat-radio-group.

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

Angular 5.2.5 Material 5.2.1 Windows 10 Pro TypeScript 2.6.2 Chrome 64.0.3282.167

Is there anything else we should know?

kwall2004 avatar Feb 21 '18 15:02 kwall2004

@josephperrott, the other issues about this were closed (the second one because of wrong formatting), but it looks like he has an important point. Considering the fact he is using separate form tags (the <form> tags are inside a custom component), something weird is happening - ngModel seems to become confused.

julianobrasil avatar Feb 21 '18 15:02 julianobrasil

I have also run into this same issue

BrianCerasuolo avatar Feb 21 '18 15:02 BrianCerasuolo

FWIW, the workaround is to ensure that the mat-radio-group name is unique across all instances of the custom component.

kwall2004 avatar Feb 21 '18 16:02 kwall2004

I think I misunderstood the previously opened issue about it.

josephperrott avatar Feb 21 '18 16:02 josephperrott

This is working as intended. mat-radio-button will uncheck all radio buttons with the same name when a radio button is clicked. Each radio group should have its own unique name. If you remove the name="radioTypeA" on mat-radio-group, radio group will automatically generate a unique name.

tinayuangao avatar Feb 23 '18 00:02 tinayuangao

Seems like a weird decision to make it less functional than a standard html radio input, but ok I guess.

kwall2004 avatar Feb 23 '18 01:02 kwall2004

@kwall2004, @tinayuangao, there's another issue tracking this behavior. It looks like it's not normal the uniqueness of the name bleeding to the outside of a form tag.

The other issue: #5983

julianobrasil avatar Feb 23 '18 02:02 julianobrasil

I think we can definitively say it's not normal.

kwall2004 avatar Feb 23 '18 02:02 kwall2004

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.