@@ -958,13 +958,7 @@ function baseInputType(scope, element, attr, ctrl, $sniffer, $browser) {
958958 // value, so it may be necessary to revalidate (by calling $setViewValue again) even if the
959959 // control's value is the same empty value twice in a row.
960960 if ( ctrl . $viewValue !== value || ( value === '' && ctrl . $$hasNativeValidators ) ) {
961- if ( scope . $root . $$phase ) {
962- ctrl . $setViewValue ( value , event ) ;
963- } else {
964- scope . $apply ( function ( ) {
965- ctrl . $setViewValue ( value , event ) ;
966- } ) ;
967- }
961+ ctrl . $setViewValue ( value , event ) ;
968962 }
969963 } ;
970964
@@ -1218,9 +1212,7 @@ function radioInputType(scope, element, attr, ctrl) {
12181212
12191213 var listener = function ( ev ) {
12201214 if ( element [ 0 ] . checked ) {
1221- scope . $apply ( function ( ) {
1222- ctrl . $setViewValue ( attr . value , ev && ev . type ) ;
1223- } ) ;
1215+ ctrl . $setViewValue ( attr . value , ev && ev . type ) ;
12241216 }
12251217 } ;
12261218
@@ -1252,9 +1244,7 @@ function checkboxInputType(scope, element, attr, ctrl, $sniffer, $browser, $filt
12521244 var falseValue = parseConstantExpr ( $parse , scope , 'ngFalseValue' , attr . ngFalseValue , false ) ;
12531245
12541246 var listener = function ( ev ) {
1255- scope . $apply ( function ( ) {
1256- ctrl . $setViewValue ( element [ 0 ] . checked , ev && ev . type ) ;
1257- } ) ;
1247+ ctrl . $setViewValue ( element [ 0 ] . checked , ev && ev . type ) ;
12581248 } ;
12591249
12601250 element . on ( 'click' , listener ) ;
@@ -1633,8 +1623,8 @@ var VALID_CLASS = 'ng-valid',
16331623 *
16341624 *
16351625 */
1636- var NgModelController = [ '$scope' , '$exceptionHandler' , '$attrs' , '$element' , '$parse' , '$animate' , '$timeout' ,
1637- function ( $scope , $exceptionHandler , $attr , $element , $parse , $animate , $timeout ) {
1626+ var NgModelController = [ '$scope' , '$exceptionHandler' , '$attrs' , '$element' , '$parse' , '$animate' , '$timeout' , '$rootScope' ,
1627+ function ( $scope , $exceptionHandler , $attr , $element , $parse , $animate , $timeout , $rootScope ) {
16381628 this . $viewValue = Number . NaN ;
16391629 this . $modelValue = Number . NaN ;
16401630 this . $validators = { } ;
@@ -2157,8 +2147,12 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
21572147 pendingDebounce = $timeout ( function ( ) {
21582148 ctrl . $commitViewValue ( ) ;
21592149 } , debounceDelay ) ;
2160- } else {
2150+ } else if ( $rootScope . $$phase ) {
21612151 ctrl . $commitViewValue ( ) ;
2152+ } else {
2153+ $scope . $apply ( function ( ) {
2154+ ctrl . $commitViewValue ( ) ;
2155+ } ) ;
21622156 }
21632157 } ;
21642158
@@ -2375,9 +2369,7 @@ var ngModelDirective = function() {
23752369 var modelCtrl = ctrls [ 0 ] ;
23762370 if ( modelCtrl . $options && modelCtrl . $options . updateOn ) {
23772371 element . on ( modelCtrl . $options . updateOn , function ( ev ) {
2378- scope . $apply ( function ( ) {
2379- modelCtrl . $$debounceViewValueCommit ( ev && ev . type ) ;
2380- } ) ;
2372+ modelCtrl . $$debounceViewValueCommit ( ev && ev . type ) ;
23812373 } ) ;
23822374 }
23832375
0 commit comments