@@ -1091,16 +1091,15 @@ function createDateInputType(type, regexp, parseDate, format) {
1091
1091
badInputChecker ( scope , element , attr , ctrl ) ;
1092
1092
baseInputType ( scope , element , attr , ctrl , $sniffer , $browser ) ;
1093
1093
var timezone = ctrl && ctrl . $options && ctrl . $options . timezone ;
1094
+ var previousDate ;
1094
1095
1095
1096
ctrl . $$parserName = type ;
1096
1097
ctrl . $parsers . push ( function ( value ) {
1097
1098
if ( ctrl . $isEmpty ( value ) ) return null ;
1098
1099
if ( regexp . test ( value ) ) {
1099
- var previousDate = ctrl . $modelValue ;
1100
- if ( previousDate && timezone === 'UTC' ) {
1101
- var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
1102
- previousDate = new Date ( previousDate . getTime ( ) + timezoneOffset ) ;
1103
- }
1100
+ // Note: We cannot read ctrl.$modelValue, as there might be a different
1101
+ // parser/formatter in the processing chain so that the model
1102
+ // contains some different data format!
1104
1103
var parsedDate = parseDate ( value , previousDate ) ;
1105
1104
if ( timezone === 'UTC' ) {
1106
1105
parsedDate . setMinutes ( parsedDate . getMinutes ( ) - parsedDate . getTimezoneOffset ( ) ) ;
@@ -1115,7 +1114,14 @@ function createDateInputType(type, regexp, parseDate, format) {
1115
1114
if ( ! isDate ( value ) ) {
1116
1115
throw $ngModelMinErr ( 'datefmt' , 'Expected `{0}` to be a date' , value ) ;
1117
1116
}
1117
+ previousDate = value ;
1118
+ if ( previousDate && timezone === 'UTC' ) {
1119
+ var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
1120
+ previousDate = new Date ( previousDate . getTime ( ) + timezoneOffset ) ;
1121
+ }
1118
1122
return $filter ( 'date' ) ( value , format , timezone ) ;
1123
+ } else {
1124
+ previousDate = null ;
1119
1125
}
1120
1126
return '' ;
1121
1127
} ) ;
@@ -1460,10 +1466,12 @@ var inputDirective = ['$browser', '$sniffer', '$filter', '$parse',
1460
1466
return {
1461
1467
restrict : 'E' ,
1462
1468
require : [ '?ngModel' ] ,
1463
- link : function ( scope , element , attr , ctrls ) {
1464
- if ( ctrls [ 0 ] ) {
1465
- ( inputType [ lowercase ( attr . type ) ] || inputType . text ) ( scope , element , attr , ctrls [ 0 ] , $sniffer ,
1466
- $browser , $filter , $parse ) ;
1469
+ link : {
1470
+ pre : function ( scope , element , attr , ctrls ) {
1471
+ if ( ctrls [ 0 ] ) {
1472
+ ( inputType [ lowercase ( attr . type ) ] || inputType . text ) ( scope , element , attr , ctrls [ 0 ] , $sniffer ,
1473
+ $browser , $filter , $parse ) ;
1474
+ }
1467
1475
}
1468
1476
}
1469
1477
} ;
@@ -2383,6 +2391,10 @@ var ngModelDirective = function() {
2383
2391
restrict : 'A' ,
2384
2392
require : [ 'ngModel' , '^?form' , '^?ngModelOptions' ] ,
2385
2393
controller : NgModelController ,
2394
+ // Prelink needs to run before any input directive
2395
+ // so that we can set the NgModelOptions in NgModelController
2396
+ // before anyone else uses it.
2397
+ priority : 1 ,
2386
2398
compile : function ngModelCompile ( element ) {
2387
2399
// Setup initial state of the control
2388
2400
element . addClass ( PRISTINE_CLASS ) . addClass ( UNTOUCHED_CLASS ) . addClass ( VALID_CLASS ) ;
0 commit comments