@@ -120,8 +120,14 @@ export abstract class MatDatepickerInputBase<S, D = ExtractDateTypeFromSelection
120120 stateChanges = new Subject < void > ( ) ;
121121
122122 /** The type of value handled by the calendar. */
123- type : MatCalendarType = 'date' ;
124-
123+ set type ( type : MatCalendarType ) {
124+ this . _type = type ;
125+ if ( this . value ) {
126+ this . _formatValue ( this . value ) ;
127+ }
128+ }
129+ protected _type : MatCalendarType = 'date' ;
130+
125131 _onTouched = ( ) => { } ;
126132 _validatorOnChange = ( ) => { } ;
127133
@@ -261,14 +267,14 @@ export abstract class MatDatepickerInputBase<S, D = ExtractDateTypeFromSelection
261267 }
262268
263269 getUnit ( ) : DateUnit {
264- switch ( this . type ) {
270+ switch ( this . _type ) {
265271 case 'date' :
266272 return 'day' ;
267273 case 'datetime' :
268274 case 'time' :
269275 return 'minute' ;
270276 default :
271- return this . type ;
277+ return this . _type ;
272278 }
273279 }
274280
@@ -313,7 +319,7 @@ export abstract class MatDatepickerInputBase<S, D = ExtractDateTypeFromSelection
313319
314320 _onInput ( value : string ) {
315321 const lastValueWasValid = this . _lastValueValid ;
316- let date = this . _dateAdapter . parse ( value , this . _dateFormats . parse [ `${ this . type } Input` ] ) ;
322+ let date = this . _dateAdapter . parse ( value , this . _dateFormats . parse [ `${ this . _type } Input` ] ) ;
317323 this . _lastValueValid = this . _isValidValue ( date ) ;
318324 date = this . _dateAdapter . getValidDateOrNull ( date ) ;
319325
@@ -351,7 +357,7 @@ export abstract class MatDatepickerInputBase<S, D = ExtractDateTypeFromSelection
351357 /** Formats a value and sets it on the input element. */
352358 protected _formatValue ( value : D | null ) {
353359 this . _elementRef . nativeElement . value = value
354- ? this . _dateAdapter . format ( value , this . _dateFormats . display [ `${ this . type } Input` ] )
360+ ? this . _dateAdapter . format ( value , this . _dateFormats . display [ `${ this . _type } Input` ] )
355361 : '' ;
356362 }
357363
0 commit comments