From 8ac6d39a1fb6ccb8da33ebc49438fe309ec1eaf5 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Mon, 20 Nov 2017 17:31:48 +0100 Subject: [PATCH] fix(radio): coerce checked input binding * Coerces the `checked` input binding for radio-buttons. This allows developers to specify the initial checked radio-button from the template. --- src/demo-app/radio/radio-demo.html | 2 +- src/lib/radio/radio.ts | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/demo-app/radio/radio-demo.html b/src/demo-app/radio/radio-demo.html index 09ecd1a2782a..c23e6b6baa1f 100644 --- a/src/demo-app/radio/radio-demo.html +++ b/src/demo-app/radio/radio-demo.html @@ -1,6 +1,6 @@

Basic Example

- Option 1 + Option 1 Option 2 Option 3 (disabled)
diff --git a/src/lib/radio/radio.ts b/src/lib/radio/radio.ts index 2d675060b090..f7788e4763f8 100644 --- a/src/lib/radio/radio.ts +++ b/src/lib/radio/radio.ts @@ -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;