mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(angular): fix ngModel accessor
This commit is contained in:
@ -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);
|
||||
});
|
||||
|
Reference in New Issue
Block a user