44 Component ,
55 ElementRef ,
66 Input ,
7+ OnChanges ,
78 OnInit ,
9+ SimpleChanges ,
810 ViewEncapsulation
911} from '@angular/core' ;
1012import { Platform } from '@angular/cdk/platform' ;
@@ -38,9 +40,11 @@ import {strings, MDCLinearProgressFoundation, MDCLinearProgressAdapter} from '@m
3840 changeDetection : ChangeDetectionStrategy . OnPush
3941} )
4042export class MdcLinearProgress extends MDCComponent < MDCLinearProgressFoundation >
41- implements MDCProgressIndicator , OnInit {
43+ implements MDCProgressIndicator , OnChanges , OnInit {
4244 _root ! : Element ;
4345
46+ private _initialized : boolean = false ;
47+
4448 /* Label indicating how the progress bar should be announced to the user. */
4549 @Input ( ) label ?: string = undefined ;
4650
@@ -50,8 +54,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
5054 }
5155 set progress ( value : number ) {
5256 this . _progress = coerceNumberProperty ( value ) ;
53- this . _foundation . setProgress ( this . _progress ) ;
54- this . _changeDetectorRef . markForCheck ( ) ;
5557 }
5658 private _progress = 0 ;
5759
@@ -61,8 +63,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
6163 }
6264 set determinate ( value : boolean ) {
6365 this . _determinate = coerceBooleanProperty ( value ) ;
64- this . _foundation . setDeterminate ( this . _determinate ) ;
65- this . _changeDetectorRef . markForCheck ( ) ;
6666 }
6767 private _determinate = false ;
6868
@@ -72,8 +72,6 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
7272 }
7373 set buffer ( value : number ) {
7474 this . _buffer = coerceNumberProperty ( value ) ;
75- this . _foundation . setBuffer ( this . _buffer ) ;
76- this . _changeDetectorRef . markForCheck ( ) ;
7775 }
7876 private _buffer = 0 ;
7977
@@ -83,8 +81,7 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
8381 }
8482 set reversed ( value : boolean ) {
8583 this . _reversed = coerceBooleanProperty ( value ) ;
86- this . _foundation . setReverse ( this . _reversed ) ;
87- this . _changeDetectorRef . markForCheck ( ) ;
84+ this . _syncReversedWithFoundation ( ) ;
8885 }
8986 private _reversed = false ;
9087
@@ -113,13 +110,34 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
113110
114111 ngOnInit ( ) : void {
115112 if ( this . _platform . isBrowser ) {
116- this . _asyncInitializeFoundation ( )
117- . then ( ( ) => {
118- this . progress = this . _progress ;
119- this . buffer = this . _buffer ;
120- this . determinate = this . _determinate ;
121- this . _changeDetectorRef . markForCheck ( ) ;
122- } ) ;
113+ this . _initialized = true ;
114+
115+ this . _foundation . init ( ) ;
116+ this . _syncProgressWithFoundation ( ) ;
117+ this . _syncBufferWithFoundation ( ) ;
118+ this . _syncDeterminateWithFoundation ( ) ;
119+ this . _syncReversedWithFoundation ( ) ;
120+
121+ this . _changeDetectorRef . markForCheck ( ) ;
122+ }
123+ }
124+
125+ ngOnChanges ( changes : SimpleChanges ) {
126+ if ( ! this . _initialized ) {
127+ return ;
128+ }
129+
130+ if ( changes [ 'progress' ] ) {
131+ this . _syncProgressWithFoundation ( ) ;
132+ }
133+ if ( changes [ 'buffer' ] ) {
134+ this . _syncBufferWithFoundation ( ) ;
135+ }
136+ if ( changes [ 'determinate' ] ) {
137+ this . _syncDeterminateWithFoundation ( ) ;
138+ }
139+ if ( changes [ 'reversed' ] ) {
140+ this . _syncReversedWithFoundation ( ) ;
123141 }
124142 }
125143
@@ -131,7 +149,19 @@ export class MdcLinearProgress extends MDCComponent<MDCLinearProgressFoundation>
131149 this . _foundation . close ( ) ;
132150 }
133151
134- async _asyncInitializeFoundation ( ) : Promise < void > {
135- this . _foundation . init ( ) ;
152+ private _syncProgressWithFoundation ( ) : void {
153+ this . _foundation . setProgress ( this . progress ) ;
154+ }
155+
156+ private _syncBufferWithFoundation ( ) : void {
157+ this . _foundation . setBuffer ( this . buffer ) ;
158+ }
159+
160+ private _syncDeterminateWithFoundation ( ) : void {
161+ this . _foundation . setDeterminate ( this . determinate ) ;
162+ }
163+
164+ private _syncReversedWithFoundation ( ) : void {
165+ this . _foundation . setReverse ( this . reversed ) ;
136166 }
137167}
0 commit comments