Skip to content

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

Closed
@pmulac

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions