Skip to content

Commit 6b92a5a

Browse files
committed
fix(inputs): ionChange is fired after updating ngModel
1 parent 59f9737 commit 6b92a5a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/util/base-input.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
9898
set value(val: T) {
9999
if (this._writeValue(val)) {
100100
this.onChange();
101+
this._fireIonChange();
101102
}
102103
}
103104

@@ -120,9 +121,14 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
120121
* @hidden
121122
*/
122123
writeValue(val: any) {
123-
this._writeValue(val);
124+
if (this._writeValue(val)) {
125+
this._fireIonChange();
126+
}
124127
}
125128

129+
/**
130+
* @hidden
131+
*/
126132
_writeValue(val: any): boolean {
127133
if (isUndefined(val)) {
128134
return false;
@@ -140,10 +146,16 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
140146
this._value = normalized;
141147
this._inputCheckHasValue(normalized);
142148
this._inputUpdated();
149+
return true;
150+
}
151+
152+
/**
153+
* @hidden
154+
*/
155+
_fireIonChange() {
143156
if (this._init) {
144157
this._debouncer.debounce(() => this.ionChange.emit(this));
145158
}
146-
return true;
147159
}
148160

149161
/**
@@ -192,8 +204,6 @@ export class BaseInput<T> extends Ion implements CommonInput<T> {
192204
if (!this._isFocus) {
193205
return;
194206
}
195-
// assert(NgZone.isInAngularZone(), 'callback should be zoned');
196-
197207
this._isFocus = false;
198208
this.ionBlur.emit(this);
199209
this._inputUpdated();

src/util/input-tester.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ function testWriteValue<T>(input: BaseInput<T>, config: TestConfig, isInit: bool
104104
let ionChangeCalled = 0;
105105
let OnChangeCalled = 0;
106106
let OnTouchedCalled = 0;
107+
let ngModelValue: any;
107108

108109
// Test ionChange
109110
let sub = input.ionChange.subscribe((ev: any) => {
110111
assertEqual(ionChangeCalled, 0, 'ionChange: internal error');
111112
assertEqual(ev, input, 'ionChange: ev is not the input');
112113
assertEqual(ev.value, test[1], 'ionChange: value does not match');
114+
assertEqual(ngModelValue, test[1], 'ionChange: ngmodel was not updated');
113115

114116
ionChangeCalled++;
115117
});
@@ -119,7 +121,7 @@ function testWriteValue<T>(input: BaseInput<T>, config: TestConfig, isInit: bool
119121
assertEqual(OnChangeCalled, 0, 'registerOnChange: internal error');
120122
assertEqual(input.value, ev, 'registerOnChange: ev output does not match');
121123
assertEqual(input.value, test[1], 'registerOnChange: value does not match');
122-
124+
ngModelValue = ev;
123125
OnChangeCalled++;
124126
});
125127

0 commit comments

Comments
 (0)