Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
Fix for ngModelChange not triggering after first value (Fixes #27)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Azar committed Mar 3, 2017
1 parent f576c82 commit 895e757
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/ng-selectize.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ export class NgSelectizeComponent implements OnInit, OnChanges, DoCheck, Control
this.onEnabledStatusChange();
}
}

if (changes.hasOwnProperty('config') && this.config) {
this.reset();
}
}

/**
* Implementing deep check for option comparison
*
* FIXME -> Implement deep check to only compare against label and value fields.
*/
ngDoCheck(): void {
if (!isEqual(this._oldOptions, this.options)) {
Expand Down Expand Up @@ -144,6 +142,7 @@ export class NgSelectizeComponent implements OnInit, OnChanges, DoCheck, Control
updatePlaceholder(): void {
this.selectize.settings.placeholder = this.getPlaceholder();
this.selectize.updatePlaceholder();
this.selectize.showInput(); // Without this, when options are cleared placeholder only appears after focus.
}

/**
Expand Down Expand Up @@ -222,6 +221,8 @@ export class NgSelectizeComponent implements OnInit, OnChanges, DoCheck, Control
* Empty check on 'obj' removed due to restriction on resetting the field.
* From testing, async should still function appropriately.
*
* FIXME This might not be necessary anymore..
*
* @param obj
*/
writeValue(obj: any): void {
Expand Down Expand Up @@ -253,8 +254,10 @@ export class NgSelectizeComponent implements OnInit, OnChanges, DoCheck, Control

set value(value: string[]) {
if (this._value !== value) {
this._value = value;
this.onChangeCallback(value);
setTimeout(() => { // Fix for change after check issue in development mode.
this._value = cloneDeep(value);
this.onChangeCallback(this._value);
});
}
}
}

0 comments on commit 895e757

Please sign in to comment.