mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
fix(angular): make sure angular form control onChange is fired when needed (#16126)
* Make sure, that angular form's onChange is not fired, when writeValue is called * Update angular/src/directives/control-value-accessors/select-value-accessor.ts Co-Authored-By: mmlleevvyy <levy@codeandmore.pl> * set muteOnChange to false by default
This commit is contained in:
@ -24,14 +24,25 @@ 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;
|
||||
|
||||
writeValue(value: any) {
|
||||
this.muteOnChange = true;
|
||||
this.element.nativeElement.checked = value;
|
||||
setIonicClasses(this.element);
|
||||
}
|
||||
|
||||
@HostListener('ionChange', ['$event.target.checked'])
|
||||
_handleIonChange(value: any) {
|
||||
this.onChange(value);
|
||||
if (!this.muteOnChange) {
|
||||
this.onChange(value);
|
||||
}
|
||||
|
||||
this.muteOnChange = false;
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
setIonicClasses(this.element);
|
||||
|
Reference in New Issue
Block a user