Skip to content

Commit

Permalink
fix(radio): coerce checked input binding (#8556)
Browse files Browse the repository at this point in the history
* Coerces the `checked` input binding for radio-buttons. This allows developers to specify the initial checked radio-button from the template.
  • Loading branch information
devversion authored and tinayuangao committed Dec 1, 2017
1 parent 53c94c7 commit f41fa8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/demo-app/radio/radio-demo.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>Basic Example</h1>
<section class="demo-section">
<mat-radio-button name="group1">Option 1</mat-radio-button>
<mat-radio-button name="group1" checked>Option 1</mat-radio-button>
<mat-radio-button name="group1">Option 2</mat-radio-button>
<mat-radio-button name="group1" disabled="true">Option 3 (disabled)</mat-radio-button>
</section>
Expand Down
7 changes: 3 additions & 4 deletions src/lib/radio/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,10 @@ export class MatRadioButton extends _MatRadioButtonMixinBase

/** Whether this radio button is checked. */
@Input()
get checked(): boolean {
return this._checked;
}
get checked(): boolean { return this._checked; }
set checked(value: boolean) {
const newCheckedState = coerceBooleanProperty(value);

set checked(newCheckedState: boolean) {
if (this._checked != newCheckedState) {
this._checked = newCheckedState;

Expand Down

0 comments on commit f41fa8c

Please sign in to comment.