diff --git a/src/framework/theme/components/radio/radio-group.component.ts b/src/framework/theme/components/radio/radio-group.component.ts index df14fe8fba..7089eba9ed 100644 --- a/src/framework/theme/components/radio/radio-group.component.ts +++ b/src/framework/theme/components/radio/radio-group.component.ts @@ -182,13 +182,10 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr writeValue(value: any): void { this.value = value; - - if (typeof value !== 'undefined') { - this.updateValues(); - } } protected updateAndSubscribeToRadios() { + this.updateValueFromCheckedOption(); this.updateNames(); this.updateValues(); this.updateDisabled(); @@ -204,9 +201,7 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr } protected updateValues() { - if (typeof this.value !== 'undefined') { - this.updateAndMarkForCheckRadios((radio: NbRadioComponent) => radio.checked = radio.value === this.value); - } + this.updateAndMarkForCheckRadios((radio: NbRadioComponent) => radio.checked = radio.value === this.value); } protected updateDisabled() { @@ -277,4 +272,12 @@ export class NbRadioGroupComponent implements AfterContentInit, OnDestroy, Contr }); } } + + protected updateValueFromCheckedOption() { + const checkedRadio = this.radios.find((radio) => radio.checked); + const isValueMissing = this.value === undefined || this.value === null; + if (checkedRadio && isValueMissing && checkedRadio.value !== this.value) { + this.value = checkedRadio.value; + } + } }