ngModel.NgModelController.$rollbackViewValue()

$rollbackViewValue();

Cancel an update and reset the input element's value to prevent an update to the $modelValue, which may be caused by a pending debounced event or because the input is waiting for a some future event.

If you have an input that uses ng-model-options to set up debounced updates or updates that depend on special events such as blur, you can have a situation where there is a period when the $viewValue is out of sync with the ngModel's $modelValue.

In this case, you can use $rollbackViewValue() to manually cancel the debounced / future update and reset the input to the last committed view value.

It is also possible that you run into difficulties if you try to update the ngModel's $modelValue programmatically before these debounced/future events have resolved/occurred, because Angular's dirty checking mechanism is not able to tell whether the model has actually changed or not.

The $rollbackViewValue() method should be called before programmatically changing the model of an input which may have such events pending. This is important in order to make sure that the input field will be updated with the new model value and any pending operations are cancelled.

doc_AngularJS
2016-03-29 16:12:15
Comments
Leave a Comment

Please login to continue.