Skip to content

Commit 082555a

Browse files
SangKavthinkxie
authored andcommitted
fix(module:radio): fix radio group trigger unnecessary ngModelChange (#904)
close #902
1 parent 44b6a0d commit 082555a

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/components/radio/nz-radio-group.component.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ export class NzRadioGroupComponent implements OnInit, AfterContentInit, ControlV
6666
radio.nzChecked = radio.nzValue === this._value;
6767
}
6868

69+
checkRadios(): void {
70+
this.radios.forEach((item) => {
71+
item.nzChecked = item.nzValue === this._value;
72+
});
73+
}
74+
6975
selectRadio(radio: NzRadioComponent | NzRadioButtonComponent): void {
7076
this.updateValue(radio.nzValue);
7177
}
@@ -76,19 +82,14 @@ export class NzRadioGroupComponent implements OnInit, AfterContentInit, ControlV
7682
}
7783
this._value = value;
7884
this.onChange(value);
79-
this.radios.forEach((item) => {
80-
item.nzChecked = item.nzValue === this._value;
81-
});
85+
this.checkRadios();
8286
}
8387

8488
constructor(private _elementRef: ElementRef, private _render: Renderer2) {
8589
this._el = this._elementRef.nativeElement;
8690
}
8791

8892
ngAfterContentInit(): void {
89-
this.radios.forEach((item) => {
90-
item.nzChecked = item.nzValue === this._value;
91-
});
9293
/** trim text node between radio button */
9394
Array.from(this._el.childNodes).forEach(node => {
9495
if (node.nodeType === 3) {
@@ -98,7 +99,8 @@ export class NzRadioGroupComponent implements OnInit, AfterContentInit, ControlV
9899
}
99100

100101
writeValue(value: string): void {
101-
this.updateValue(value);
102+
this._value = value;
103+
this.checkRadios();
102104
}
103105

104106
registerOnChange(fn: (_: string) => void): void {

0 commit comments

Comments
 (0)