From 505d27ad34e0764a36d6deb355f09c409821192d Mon Sep 17 00:00:00 2001 From: Manuel Mtz-Almeida Date: Thu, 27 Apr 2017 18:35:08 +0200 Subject: [PATCH] fix(base-input): first ngModel update is not dispatched --- src/util/base-input.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/util/base-input.ts b/src/util/base-input.ts index 09916db176..3e9b07314e 100644 --- a/src/util/base-input.ts +++ b/src/util/base-input.ts @@ -38,6 +38,8 @@ export class BaseInput extends Ion implements CommonInput { _disabled: boolean = false; _debouncer: TimeoutDebouncer = new TimeoutDebouncer(0); _init: boolean = false; + _initModel: boolean = false; + id: string; /** @@ -122,8 +124,14 @@ export class BaseInput extends Ion implements CommonInput { */ writeValue(val: any) { if (this._writeValue(val)) { - this._fireIonChange(); + if (this._initModel) { + this._fireIonChange(); + } else if (this._init) { + // ngModel fires the first time too late, we need to skip the first ngModel update + this._initModel = true; + } } + } /** @@ -161,6 +169,7 @@ export class BaseInput extends Ion implements CommonInput { this._debouncer.debounce(() => { assert(NgZone.isInAngularZone(), 'IonChange: should be zoned'); this.ionChange.emit(this._inputChangeEvent()); + this._initModel = true; }); } }