If I bind a variable to ngModel, that value will not get updated before onChangeState callback. Within the callback for onChangeState, event.previousValue and event.currentValue are correct. However, the variable binded to ngModel is not yet updated.
The fix seems to be in directive.ts, setStateValue() function. This will allow angular's ControlValueAccessor registerOnChange() to update ngModel before the onChangeState event is fired.
The fix that worked for me:
private setStateValue(v: boolean): void {
if (v !== this._innerState) {
this._onChangeCallback(v); // Moved above emit
this.onChangeState.emit({
previousValue: this._innerState,
currentValue: v
});
this._innerState = v;
}
}
If I bind a variable to ngModel, that value will not get updated before onChangeState callback. Within the callback for onChangeState, event.previousValue and event.currentValue are correct. However, the variable binded to ngModel is not yet updated.
The fix seems to be in directive.ts, setStateValue() function. This will allow angular's ControlValueAccessor registerOnChange() to update ngModel before the onChangeState event is fired.
The fix that worked for me: