@@ -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 ( ) ) ;
@@ -1112,7 +1111,14 @@ function createDateInputType(type, regexp, parseDate, format) {
1112
1111
1113
1112
ctrl . $formatters . push ( function ( value ) {
1114
1113
if ( isDate ( value ) ) {
1114
+ previousDate = value ;
1115
+ if ( previousDate && timezone === 'UTC' ) {
1116
+ var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
1117
+ previousDate = new Date ( previousDate . getTime ( ) + timezoneOffset ) ;
1118
+ }
1115
1119
return $filter ( 'date' ) ( value , format , timezone ) ;
1120
+ } else {
1121
+ previousDate = null ;
1116
1122
}
1117
1123
return '' ;
1118
1124
} ) ;
@@ -1452,10 +1458,12 @@ var inputDirective = ['$browser', '$sniffer', '$filter', '$parse',
1452
1458
return {
1453
1459
restrict : 'E' ,
1454
1460
require : [ '?ngModel' ] ,
1455
- link : function ( scope , element , attr , ctrls ) {
1456
- if ( ctrls [ 0 ] ) {
1457
- ( inputType [ lowercase ( attr . type ) ] || inputType . text ) ( scope , element , attr , ctrls [ 0 ] , $sniffer ,
1458
- $browser , $filter , $parse ) ;
1461
+ link : {
1462
+ pre : function ( scope , element , attr , ctrls ) {
1463
+ if ( ctrls [ 0 ] ) {
1464
+ ( inputType [ lowercase ( attr . type ) ] || inputType . text ) ( scope , element , attr , ctrls [ 0 ] , $sniffer ,
1465
+ $browser , $filter , $parse ) ;
1466
+ }
1459
1467
}
1460
1468
}
1461
1469
} ;
@@ -2375,6 +2383,10 @@ var ngModelDirective = function() {
2375
2383
restrict : 'A' ,
2376
2384
require : [ 'ngModel' , '^?form' , '^?ngModelOptions' ] ,
2377
2385
controller : NgModelController ,
2386
+ // Prelink needs to run before any input directive
2387
+ // so that we can set the NgModelOptions in NgModelController
2388
+ // before anyone else uses it.
2389
+ priority : 1 ,
2378
2390
compile : function ngModelCompile ( element ) {
2379
2391
// Setup initial state of the control
2380
2392
element . addClass ( PRISTINE_CLASS ) . addClass ( UNTOUCHED_CLASS ) . addClass ( VALID_CLASS ) ;
0 commit comments