This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ngModelOptions): move debounce and updateOn logic into NgMod…
…elController Move responsibility for pending and debouncing model updates into `NgModelController`. Now input directives are only responsible for capturing changes to the input element's value and then calling `$setViewValue` with the new value. Calls to `$setViewValue(value)` change the `$viewValue` property but these changes are not committed to the `$modelValue` until an `updateOn` trigger occurs (and any related `debounce` has resolved). The `$$lastCommittedViewValue` is now stored when `$setViewValue(value)` updates the `$viewValue`, which allows the view to be "reset" by calling `$rollbackViewValue()`. The new `$commitViewValue()` method allows developers to force the `$viewValue` to be committed through to the `$modelValue` immediately, ignoring `updateOn` triggers and `debounce` delays. BREAKING CHANGE: This commit changes the API on `NgModelController`, both semantically and in terms of adding and renaming methods. * `$setViewValue(value)` - This method still changes the `$viewValue` but does not immediately commit this change through to the `$modelValue` as it did previously. Now the value is committed only when a trigger specified in an associated `ngModelOptions` directive occurs. If `ngModelOptions` also has a `debounce` delay specified for the trigger then the change will also be debounced before being committed. In most cases this should not have a significant impact on how `NgModelController` is used: If `updateOn` includes `default` then `$setViewValue` will trigger a (potentially debounced) commit immediately. * `$cancelUpdate()` - is renamed to `$rollbackViewValue()` and has the same meaning, which is to revert the current `$viewValue` back to the `$lastCommittedViewValue`, to cancel any pending debounced updates and to re-render the input. To migrate code that used `$cancelUpdate()` follow the example below: Before: ``` $scope.resetWithCancel = function (e) { if (e.keyCode == 27) { $scope.myForm.myInput1.$cancelUpdate(); $scope.myValue = ''; } }; ``` After: ``` $scope.resetWithCancel = function (e) { if (e.keyCode == 27) { $scope.myForm.myInput1.$rollbackViewValue(); $scope.myValue = ''; } } ```
- Loading branch information
1 parent
0ef1727
commit adfc322
Showing
2 changed files
with
155 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
adfc322
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 was using the code above to make my fields dirty inside a directive. It just stopped working after this change.
How can I do it instead?
adfc322
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.
Not sure what you mean, can you open an issue with a plunkr example of the problem?