@@ -1756,11 +1756,6 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
1756
1756
var parentForm = $element . inheritedData ( '$formController' ) || nullFormCtrl ,
1757
1757
currentValidationRunId = 0 ;
1758
1758
1759
- // Setup initial state of the control
1760
- $element
1761
- . addClass ( PRISTINE_CLASS )
1762
- . addClass ( UNTOUCHED_CLASS ) ;
1763
-
1764
1759
/**
1765
1760
* @ngdoc method
1766
1761
* @name ngModel.NgModelController#$setValidity
@@ -2380,42 +2375,47 @@ var ngModelDirective = function() {
2380
2375
restrict : 'A' ,
2381
2376
require : [ 'ngModel' , '^?form' , '^?ngModelOptions' ] ,
2382
2377
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 ) ;
2387
2381
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 ;
2389
2386
2390
- // notify others, especially parent forms
2391
- formCtrl . $addControl ( modelCtrl ) ;
2387
+ modelCtrl . $$setOptions ( ctrls [ 2 ] && ctrls [ 2 ] . $options ) ;
2392
2388
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 ) ;
2398
2391
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
+ }
2408
2396
} ) ;
2409
- }
2410
2397
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 ;
2413
2412
2414
- scope . $apply ( function ( ) {
2415
- modelCtrl . $setTouched ( ) ;
2413
+ scope . $apply ( function ( ) {
2414
+ modelCtrl . $setTouched ( ) ;
2415
+ } ) ;
2416
2416
} ) ;
2417
- } ) ;
2418
- }
2417
+ }
2418
+ } ;
2419
2419
}
2420
2420
} ;
2421
2421
} ;
@@ -2970,8 +2970,9 @@ function addSetValidityMethod(context) {
2970
2970
parentForm = context . parentForm ,
2971
2971
$animate = context . $animate ;
2972
2972
2973
+ classCache [ INVALID_CLASS ] = ! ( classCache [ VALID_CLASS ] = $element . hasClass ( VALID_CLASS ) ) ;
2974
+
2973
2975
ctrl . $setValidity = setValidity ;
2974
- toggleValidationCss ( '' , true ) ;
2975
2976
2976
2977
function setValidity ( validationErrorKey , state , options ) {
2977
2978
if ( state === undefined ) {
0 commit comments