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