This repository was 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.3k
fix(ngModel): use $evalAsync for blur events to safely $apply
#9808
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
fix:(input) asynchronous ng-model blur
If the model is blurred during an apply it should trigger the $touched asynchronously. Fixes #8762
- Loading branch information
commit cb540c71a76dba6285ad05e582781a04816d573b
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1144,6 +1144,32 @@ describe('ngModel', function() { | |
| dealoc(element); | ||
| })); | ||
|
|
||
| it('should digest asynchronously on "blur" event if a apply is already in progress', | ||
| inject(function($compile, $rootScope) { | ||
|
|
||
| var element = $compile('<form name="myForm">' + | ||
| '<input name="myControl" ng-model="value" >' + | ||
| '</form>')($rootScope); | ||
| var inputElm = element.find('input'); | ||
| var control = $rootScope.myForm.myControl; | ||
|
|
||
| $rootScope.$apply(function() { | ||
| expect(control.$touched).toBe(false); | ||
|
Contributor
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. Is there a specifc reason why the first two expects are inside the $apply block?
Contributor
Author
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. @Narretz there is no specific reason for the two expects to be in there. Do you think it would be better to move them just before the apply block? I was just trying to ensure that the touched and untouched state remained exactly the same before and after the blur event. |
||
| expect(control.$untouched).toBe(true); | ||
|
|
||
| browserTrigger(inputElm, 'blur'); | ||
|
|
||
| expect(control.$touched).toBe(false); | ||
| expect(control.$untouched).toBe(true); | ||
| }); | ||
|
|
||
| expect(control.$touched).toBe(true); | ||
| expect(control.$untouched).toBe(false); | ||
|
|
||
| dealoc(element); | ||
| })); | ||
|
|
||
|
|
||
| it('should register/deregister a nested ngModel with parent form when entering or leaving DOM', | ||
| inject(function($compile, $rootScope) { | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You should check
$rootScope.$phase, like here https://github.com/angular/angular.js/blob/master/src/ng/directive/ngEventDirs.js#L62There 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.
@Narretz means
$rootScope.$$phase(just clearing it up to avoid confusion 😈).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.
Sounds good I'll try to update that. I followed 719c747#diff-eefe7d65b6795cba34d2b08a27ebf2beR63 which only checked
scope.$$phase.Just to help my understanding is there a reason
$rootScope.$$phaseisn't used there? @tbosch thanks!Ahh, sorry I see now, it came afterwards I should have checked the most recent version. Thanks for the tips guys.
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.
Thanks for the clarification @gkalpak Why $rootScope is explained here: #8849 (comment)