Skip to content

Commit

Permalink
fix(module:radio): value can not be dynamically update (#677)
Browse files Browse the repository at this point in the history
close #668 

* fix(module:radio): value can not be dynamically update

* refactor(module:radio): use Render2 instead of Render
  • Loading branch information
hsuanxyz authored and vthinkxie committed Dec 6, 2017
1 parent 8665639 commit bedcf96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/components/radio/nz-radio-group.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Input,
ElementRef,
AfterContentInit,
Renderer,
Renderer2,
HostBinding,
forwardRef
} from '@angular/core';
Expand Down Expand Up @@ -63,25 +63,26 @@ export class NzRadioGroupComponent implements OnInit, AfterContentInit, ControlV

addRadio(radio: NzRadioComponent | NzRadioButtonComponent) {
this.radios.push(radio);
radio.nzChecked = radio.nzValue === this._value
}

selectRadio(radio: NzRadioComponent | NzRadioButtonComponent) {
this.updateValue(radio.nzValue);
this.onChange(radio.nzValue);
}

updateValue(value: any) {
if (this._value === value) {
return;
}
this._value = value;
this.onChange(value);
this.radios.forEach((item) => {
item.nzChecked = item.nzValue === this._value;
});
}


constructor(private _elementRef: ElementRef, private _render: Renderer) {
constructor(private _elementRef: ElementRef, private _render: Renderer2) {
this._el = this._elementRef.nativeElement;
}

Expand Down Expand Up @@ -116,6 +117,6 @@ export class NzRadioGroupComponent implements OnInit, AfterContentInit, ControlV
}

ngOnInit() {
this._render.setElementClass(this._el, `${this._prefixCls}`, true);
this._render.addClass(this._el, `${this._prefixCls}`);
}
}
2 changes: 1 addition & 1 deletion src/components/radio/nz-radio.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ export class NzRadioComponent implements OnInit {

constructor(private _elementRef: ElementRef, public _renderer: Renderer2, public _nzRadioGroup: NzRadioGroupComponent) {
this._el = this._elementRef.nativeElement;
this._nzRadioGroup.addRadio(this);
}

ngOnInit() {
this._nzRadioGroup.addRadio(this);
this._renderer.addClass(this._el, `${this._prefixCls}-wrapper`);
this.setClassMap();
}
Expand Down

0 comments on commit bedcf96

Please sign in to comment.