@@ -2053,9 +2053,11 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2053
2053
} ;
2054
2054
2055
2055
this . $$parseAndValidate = function ( ) {
2056
+ var pendingClassChanges = null ;
2056
2057
var viewValue = ctrl . $$lastCommittedViewValue ;
2057
2058
var modelValue = viewValue ;
2058
2059
var parserValid = isUndefined ( modelValue ) ? undefined : true ;
2060
+ var flushPendingClassChanges = schedulePendingClassChanges ( $scope , ctrl , $element , $animate ) ;
2059
2061
2060
2062
if ( parserValid ) {
2061
2063
for ( var i = 0 ; i < ctrl . $parsers . length ; i ++ ) {
@@ -2092,6 +2094,8 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2092
2094
ctrl . $$writeModelToScope ( ) ;
2093
2095
}
2094
2096
}
2097
+
2098
+ flushPendingClassChanges ( ) ;
2095
2099
} ;
2096
2100
2097
2101
this . $$writeModelToScope = function ( ) {
@@ -2197,7 +2201,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2197
2201
// TODO(perf): why not move this to the action fn?
2198
2202
if ( modelValue !== ctrl . $modelValue ) {
2199
2203
ctrl . $modelValue = modelValue ;
2200
-
2204
+ var flushPendingClassChanges = schedulePendingClassChanges ( $scope , ctrl , $element , $animate ) ;
2201
2205
var formatters = ctrl . $formatters ,
2202
2206
idx = formatters . length ;
2203
2207
@@ -2211,13 +2215,45 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
2211
2215
2212
2216
ctrl . $$runValidators ( undefined , modelValue , viewValue , noop ) ;
2213
2217
}
2218
+ flushPendingClassChanges ( ) ;
2214
2219
}
2215
2220
2216
2221
return modelValue ;
2217
2222
} ) ;
2218
2223
} ] ;
2219
2224
2220
2225
2226
+ function schedulePendingClassChanges ( scope , ctrl , element , animate ) {
2227
+ if ( ! ctrl . $$pendingClassChanges ) {
2228
+ ctrl . $$pendingClassChanges = { } ;
2229
+
2230
+ if ( scope . $$phase || scope . $root . $$phase ) {
2231
+ scope . $$postDigest ( flushPendingClassChangesImmediately ) ;
2232
+ } else {
2233
+ return flushPendingClassChangesImmediately ;
2234
+ }
2235
+ }
2236
+ return noop ;
2237
+
2238
+ function flushPendingClassChangesImmediately ( ) {
2239
+ flushPendingClassChanges ( animate , element , ctrl . $$pendingClassChanges ) ;
2240
+ ctrl . $$pendingClassChanges = null ;
2241
+ }
2242
+ }
2243
+
2244
+
2245
+ function flushPendingClassChanges ( $animate , element , pendingChanges ) {
2246
+ var keys = Object . keys ( pendingChanges ) ;
2247
+
2248
+ for ( var i = 0 , ii = keys . length ; i < ii ; ++ i ) {
2249
+ var key = keys [ i ] ;
2250
+ var value = pendingChanges [ key ] ;
2251
+ if ( value < 0 ) $animate . removeClass ( element , key ) ;
2252
+ else if ( value > 0 ) $animate . addClass ( element , key ) ;
2253
+ }
2254
+ }
2255
+
2256
+
2221
2257
/**
2222
2258
* @ngdoc directive
2223
2259
* @name ngModel
@@ -3037,6 +3073,18 @@ function addSetValidityMethod(context) {
3037
3073
}
3038
3074
3039
3075
function cachedToggleClass ( className , switchValue ) {
3076
+ var pendingChanges = ctrl . $$pendingClassChanges ;
3077
+ if ( pendingChanges ) {
3078
+ if ( switchValue ) {
3079
+ pendingChanges [ className ] = 1 ;
3080
+ classCache [ className ] = true ;
3081
+ } else {
3082
+ pendingChanges [ className ] = - 1 ;
3083
+ classCache [ className ] = false ;
3084
+ }
3085
+ return ;
3086
+ }
3087
+
3040
3088
if ( switchValue && ! classCache [ className ] ) {
3041
3089
$animate . addClass ( $element , className ) ;
3042
3090
classCache [ className ] = true ;
0 commit comments