File tree 2 files changed +34
-3
lines changed
2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -2460,9 +2460,14 @@ var ngModelDirective = function() {
2460
2460
element . on ( 'blur' , function ( ev ) {
2461
2461
if ( modelCtrl . $touched ) return ;
2462
2462
2463
- scope . $apply ( function ( ) {
2464
- modelCtrl . $setTouched ( ) ;
2465
- } ) ;
2463
+ var onBlurSetTouched = function ( ) {
2464
+ modelCtrl . $setTouched ( ) ;
2465
+ } ;
2466
+ if ( scope . $$phase ) {
2467
+ scope . $evalAsync ( onBlurSetTouched ) ;
2468
+ } else {
2469
+ scope . $apply ( onBlurSetTouched ) ;
2470
+ }
2466
2471
} ) ;
2467
2472
}
2468
2473
} ;
Original file line number Diff line number Diff line change @@ -1144,6 +1144,32 @@ describe('ngModel', function() {
1144
1144
dealoc ( element ) ;
1145
1145
} ) ) ;
1146
1146
1147
+ it ( 'should digest asynchronously on "blur" event if a apply is already in progress' ,
1148
+ inject ( function ( $compile , $rootScope ) {
1149
+
1150
+ var element = $compile ( '<form name="myForm">' +
1151
+ '<input name="myControl" ng-model="value" >' +
1152
+ '</form>' ) ( $rootScope ) ;
1153
+ var inputElm = element . find ( 'input' ) ;
1154
+ var control = $rootScope . myForm . myControl ;
1155
+
1156
+ $rootScope . $apply ( function ( ) {
1157
+ expect ( control . $touched ) . toBe ( false ) ;
1158
+ expect ( control . $untouched ) . toBe ( true ) ;
1159
+
1160
+ browserTrigger ( inputElm , 'blur' ) ;
1161
+
1162
+ expect ( control . $touched ) . toBe ( false ) ;
1163
+ expect ( control . $untouched ) . toBe ( true ) ;
1164
+ } ) ;
1165
+
1166
+ expect ( control . $touched ) . toBe ( true ) ;
1167
+ expect ( control . $untouched ) . toBe ( false ) ;
1168
+
1169
+ dealoc ( element ) ;
1170
+ } ) ) ;
1171
+
1172
+
1147
1173
it ( 'should register/deregister a nested ngModel with parent form when entering or leaving DOM' ,
1148
1174
inject ( function ( $compile , $rootScope ) {
1149
1175
You can’t perform that action at this time.
0 commit comments