fix(angular): fix ngModel accessor

This commit is contained in:
Manu Mtz.-Almeida
2018-10-31 19:19:13 +01:00
parent 8eacad2d06
commit fab8b604a5
5 changed files with 20 additions and 56 deletions

View File

@ -23,27 +23,20 @@ export class BooleanValueAccessor implements ControlValueAccessor {
onChange: (value: any) => void;
onTouched: () => void;
/**
* Whether onChange should be mutted (not be fired). Will be true only when writeValue was called, which
* means that value changed inside angular form (e.g. calling setValue on a control).
*/
private muteOnChange = false;
private lastValue: any;
writeValue(value: any) {
this.muteOnChange = true;
this.element.nativeElement.checked = value;
this.element.nativeElement.checked = this.lastValue = value;
setIonicClasses(this.element);
}
@HostListener('ionChange', ['$event.target.checked'])
_handleIonChange(value: any) {
if (!this.muteOnChange) {
if (value !== this.lastValue) {
this.lastValue = value;
this.onChange(value);
}
this.muteOnChange = false;
requestAnimationFrame(() => {
setIonicClasses(this.element);
});