-
Notifications
You must be signed in to change notification settings - Fork 27.5k
fix(ng-model-options): Canceling debounces now forces a view reset #7011
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1701,10 +1701,13 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |
* This method should be called before directly update a debounced model from the scope in | ||
* order to prevent unintended future changes of the model value because of a delayed event. | ||
*/ | ||
this.$cancelDebounce = function() { | ||
this.$cancelDebounce = function(skipRender) { | ||
if ( pendingDebounce ) { | ||
$timeout.cancel(pendingDebounce); | ||
pendingDebounce = null; | ||
if ( !skipRender ) { | ||
this.$resetModelValue(); | ||
} | ||
} | ||
}; | ||
|
||
|
@@ -1769,7 +1772,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |
? (this.$options.debounce[trigger] || this.$options.debounce['default'] || 0) | ||
: this.$options.debounce) || 0; | ||
|
||
that.$cancelDebounce(); | ||
that.$cancelDebounce(true); | ||
if ( debounceDelay ) { | ||
pendingDebounce = $timeout(function() { | ||
pendingDebounce = null; | ||
|
@@ -1783,6 +1786,20 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ | |
// model -> value | ||
var ctrl = this; | ||
|
||
this.$resetModelValue = function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was wondering about that. Something like like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just call this fn from ngModelWatch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var formatters = ctrl.$formatters, | ||
idx = formatters.length; | ||
|
||
var value = ngModelGet($scope); | ||
ctrl.$modelValue = value; | ||
while(idx--) { | ||
value = formatters[idx](value); | ||
} | ||
|
||
ctrl.$viewValue = value; | ||
ctrl.$render(); | ||
}; | ||
|
||
$scope.$watch(function ngModelWatch() { | ||
var value = ngModelGet($scope); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should rename this
skipReset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I'll also document the new parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
skipViewValReset
to make it more explicit?