66 * found in the LICENSE file at https://angular.io/license
77 */
88
9+ import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
910import {
11+ AfterContentInit ,
1012 ChangeDetectionStrategy ,
1113 ChangeDetectorRef ,
1214 Component ,
@@ -16,12 +18,11 @@ import {
1618 SimpleChanges ,
1719 ViewEncapsulation ,
1820} from '@angular/core' ;
19- import { MatDatepicker } from './datepicker' ;
20- import { MatDatepickerIntl } from './datepicker-intl' ;
21- import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
22- import { Subscription } from 'rxjs/Subscription' ;
2321import { merge } from 'rxjs/observable/merge' ;
2422import { of as observableOf } from 'rxjs/observable/of' ;
23+ import { Subscription } from 'rxjs/Subscription' ;
24+ import { MatDatepicker } from './datepicker' ;
25+ import { MatDatepickerIntl } from './datepicker-intl' ;
2526
2627
2728@Component ( {
@@ -35,7 +36,7 @@ import {of as observableOf} from 'rxjs/observable/of';
3536 preserveWhitespaces : false ,
3637 changeDetection : ChangeDetectionStrategy . OnPush ,
3738} )
38- export class MatDatepickerToggle < D > implements OnChanges , OnDestroy {
39+ export class MatDatepickerToggle < D > implements AfterContentInit , OnChanges , OnDestroy {
3940 private _stateChanges = Subscription . EMPTY ;
4041
4142 /** Datepicker instance that the button will toggle. */
@@ -44,39 +45,43 @@ export class MatDatepickerToggle<D> implements OnChanges, OnDestroy {
4445 /** Whether the toggle button is disabled. */
4546 @Input ( )
4647 get disabled ( ) : boolean {
47- return this . _disabled === undefined ? this . datepicker . disabled : this . _disabled ;
48+ return this . _disabled === undefined ? this . datepicker . disabled : ! ! this . _disabled ;
4849 }
49- set disabled ( value ) {
50+ set disabled ( value : boolean ) {
5051 this . _disabled = coerceBooleanProperty ( value ) ;
5152 }
5253 private _disabled : boolean ;
5354
54- constructor (
55- public _intl : MatDatepickerIntl ,
56- private _changeDetectorRef : ChangeDetectorRef ) { }
55+ constructor ( public _intl : MatDatepickerIntl , private _changeDetectorRef : ChangeDetectorRef ) { }
5756
5857 ngOnChanges ( changes : SimpleChanges ) {
5958 if ( changes . datepicker ) {
60- const datepicker : MatDatepicker < D > = changes . datepicker . currentValue ;
61- const datepickerDisabled = datepicker ? datepicker . _disabledChange : observableOf ( ) ;
62- const inputDisabled = datepicker && datepicker . _datepickerInput ?
63- datepicker . _datepickerInput . _disabledChange :
64- observableOf ( ) ;
65-
66- this . _stateChanges . unsubscribe ( ) ;
67- this . _stateChanges = merge ( this . _intl . changes , datepickerDisabled , inputDisabled )
68- . subscribe ( ( ) => this . _changeDetectorRef . markForCheck ( ) ) ;
59+ this . _watchStateChanges ( ) ;
6960 }
7061 }
7162
7263 ngOnDestroy ( ) {
7364 this . _stateChanges . unsubscribe ( ) ;
7465 }
7566
67+ ngAfterContentInit ( ) {
68+ this . _watchStateChanges ( ) ;
69+ }
70+
7671 _open ( event : Event ) : void {
7772 if ( this . datepicker && ! this . disabled ) {
7873 this . datepicker . open ( ) ;
7974 event . stopPropagation ( ) ;
8075 }
8176 }
77+
78+ private _watchStateChanges ( ) {
79+ const datepickerDisabled = this . datepicker ? this . datepicker . _disabledChange : observableOf ( ) ;
80+ const inputDisabled = this . datepicker && this . datepicker . _datepickerInput ?
81+ this . datepicker . _datepickerInput . _disabledChange : observableOf ( ) ;
82+
83+ this . _stateChanges . unsubscribe ( ) ;
84+ this . _stateChanges = merge ( this . _intl . changes , datepickerDisabled , inputDisabled )
85+ . subscribe ( ( ) => this . _changeDetectorRef . markForCheck ( ) ) ;
86+ }
8287}
0 commit comments