@@ -1756,11 +1756,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
17561756 var parentForm = $element . inheritedData ( '$formController' ) || nullFormCtrl ,
17571757 currentValidationRunId = 0 ;
17581758
1759- // Setup initial state of the control
1760- $element
1761- . addClass ( PRISTINE_CLASS )
1762- . addClass ( UNTOUCHED_CLASS ) ;
1763-
17641759 /**
17651760 * @ngdoc method
17661761 * @name ngModel.NgModelController#$setValidity
@@ -2380,42 +2375,47 @@ var ngModelDirective = function() {
23802375 restrict : 'A' ,
23812376 require : [ 'ngModel' , '^?form' , '^?ngModelOptions' ] ,
23822377 controller : NgModelController ,
2383- link : {
2384- pre : function ( scope , element , attr , ctrls ) {
2385- var modelCtrl = ctrls [ 0 ] ,
2386- formCtrl = ctrls [ 1 ] || nullFormCtrl ;
2378+ compile : function ngModelCompile ( element ) {
2379+ // Setup initial state of the control
2380+ element . addClass ( PRISTINE_CLASS ) . addClass ( UNTOUCHED_CLASS ) . addClass ( VALID_CLASS ) ;
23872381
2388- modelCtrl . $$setOptions ( ctrls [ 2 ] && ctrls [ 2 ] . $options ) ;
2382+ return {
2383+ pre : function ngModelPreLink ( scope , element , attr , ctrls ) {
2384+ var modelCtrl = ctrls [ 0 ] ,
2385+ formCtrl = ctrls [ 1 ] || nullFormCtrl ;
23892386
2390- // notify others, especially parent forms
2391- formCtrl . $addControl ( modelCtrl ) ;
2387+ modelCtrl . $$setOptions ( ctrls [ 2 ] && ctrls [ 2 ] . $options ) ;
23922388
2393- attr . $observe ( 'name' , function ( newValue ) {
2394- if ( modelCtrl . $name !== newValue ) {
2395- formCtrl . $$renameControl ( modelCtrl , newValue ) ;
2396- }
2397- } ) ;
2389+ // notify others, especially parent forms
2390+ formCtrl . $addControl ( modelCtrl ) ;
23982391
2399- scope . $on ( '$destroy' , function ( ) {
2400- formCtrl . $removeControl ( modelCtrl ) ;
2401- } ) ;
2402- } ,
2403- post : function ( scope , element , attr , ctrls ) {
2404- var modelCtrl = ctrls [ 0 ] ;
2405- if ( modelCtrl . $options && modelCtrl . $options . updateOn ) {
2406- element . on ( modelCtrl . $options . updateOn , function ( ev ) {
2407- modelCtrl . $$debounceViewValueCommit ( ev && ev . type ) ;
2392+ attr . $observe ( 'name' , function ( newValue ) {
2393+ if ( modelCtrl . $name !== newValue ) {
2394+ formCtrl . $$renameControl ( modelCtrl , newValue ) ;
2395+ }
24082396 } ) ;
2409- }
24102397
2411- element . on ( 'blur' , function ( ev ) {
2412- if ( modelCtrl . $touched ) return ;
2398+ scope . $on ( '$destroy' , function ( ) {
2399+ formCtrl . $removeControl ( modelCtrl ) ;
2400+ } ) ;
2401+ } ,
2402+ post : function ngModelPostLink ( scope , element , attr , ctrls ) {
2403+ var modelCtrl = ctrls [ 0 ] ;
2404+ if ( modelCtrl . $options && modelCtrl . $options . updateOn ) {
2405+ element . on ( modelCtrl . $options . updateOn , function ( ev ) {
2406+ modelCtrl . $$debounceViewValueCommit ( ev && ev . type ) ;
2407+ } ) ;
2408+ }
2409+
2410+ element . on ( 'blur' , function ( ev ) {
2411+ if ( modelCtrl . $touched ) return ;
24132412
2414- scope . $apply ( function ( ) {
2415- modelCtrl . $setTouched ( ) ;
2413+ scope . $apply ( function ( ) {
2414+ modelCtrl . $setTouched ( ) ;
2415+ } ) ;
24162416 } ) ;
2417- } ) ;
2418- }
2417+ }
2418+ } ;
24192419 }
24202420 } ;
24212421} ;
@@ -2970,8 +2970,9 @@ function addSetValidityMethod(context) {
29702970 parentForm = context . parentForm ,
29712971 $animate = context . $animate ;
29722972
2973+ classCache [ INVALID_CLASS ] = ! ( classCache [ VALID_CLASS ] = $element . hasClass ( VALID_CLASS ) ) ;
2974+
29732975 ctrl . $setValidity = setValidity ;
2974- toggleValidationCss ( '' , true ) ;
29752976
29762977 function setValidity ( validationErrorKey , state , options ) {
29772978 if ( state === undefined ) {
0 commit comments