Skip to content

Radio buttons do not become unchecked when a bound ngModel property is removed #327

Closed

Description

@pmulac

Consider the following radio group:

<md-radio-group  [ngModel]="model.accountType" ngControl="accountType">
    <md-radio-button value="I">Individual</md-radio-button>
    <md-radio-button value="J">Joint</md-radio-button>
</md-radio-group>

And then the ngModel object changes like so:

Original state: {accountType: 'J'}
New state: {}

I would expect the corresponding radio button ('Joint') to be unchecked. However, the 'Joint' radio button remains checked, which does not represent the true state of the control.

As a workaround, I'm able to bind to the md-radio-checked class on each button, which removes the checked state of a radio button when the corresponding binding changes to undefined.

<md-radio-group  [ngModel]="model.accountType" ngControl="accountType">
    <md-radio-button value="I" [class.md-radio-checked]="model.accountType === 'I'">Individual</md-radio-button>
    <md-radio-button value="J" [class.md-radio-checked]="model.accountType === 'J'">Joint</md-radio-button>
</md-radio-group>

This is especially important for a redux/ngrx application, in which you would expect radio buttons to become checked/unchecked as you replay recorded actions.

Activity

  1. added
    P3
    on Apr 18, 2016
  2. added this to the alpha.5 milestone on Apr 18, 2016
  3. added a commit that references this issue on May 18, 2016
    8af16e8
  4. lobo-tuerto commented on Apr 2, 2017

    @lobo-tuerto

    I'm observing the same behavior with reactive forms :(

  5. angular-automatic-lock-bot commented on Sep 5, 2019

    @angular-automatic-lock-bot

    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.

  6. locked and limited conversation to collaborators on Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions