From f41fa8c1addc7d385f6b9ecc1cd83e5112256859 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Fri, 1 Dec 2017 19:48:47 +0100 Subject: [PATCH] fix(radio): coerce checked input binding (#8556) * 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 06b0d4e454f0..8c3ff6cc629a 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;