@@ -3,12 +3,12 @@ import {
33 ModuleWithProviders ,
44 Component ,
55 HostBinding ,
6- ChangeDetectorRef ,
76 ChangeDetectionStrategy ,
87 OnDestroy ,
98 Input ,
109 ElementRef ,
11- NgZone
10+ NgZone ,
11+ Renderer
1212} from '@angular/core' ;
1313import { DefaultStyleCompatibilityModeModule } from '../core' ;
1414
@@ -43,10 +43,7 @@ type EasingFn = (currentTime: number, startValue: number,
4343 host : {
4444 'role' : 'progressbar' ,
4545 '[attr.aria-valuemin]' : '_ariaValueMin' ,
46- '[attr.aria-valuemax]' : '_ariaValueMax' ,
47- '[class.md-primary]' : 'color == "primary"' ,
48- '[class.md-accent]' : 'color == "accent"' ,
49- '[class.md-warn]' : 'color == "warn"' ,
46+ '[attr.aria-valuemax]' : '_ariaValueMax'
5047 } ,
5148 templateUrl : 'progress-spinner.html' ,
5249 styleUrls : [ 'progress-spinner.css' ] ,
@@ -62,6 +59,10 @@ export class MdProgressSpinner implements OnDestroy {
6259 /** The SVG <path> node that is used to draw the circle. */
6360 private _path : SVGPathElement ;
6461
62+ private _mode : ProgressSpinnerMode = 'determinate' ;
63+ private _value : number ;
64+ private _color : string = 'primary' ;
65+
6566 /**
6667 * Values for aria max and min are only defined as numbers when in a determinate mode. We do this
6768 * because voiceover does not report the progress indicator as indeterminate if the aria min
@@ -92,8 +93,14 @@ export class MdProgressSpinner implements OnDestroy {
9293 this . _cleanupIndeterminateAnimation ( ) ;
9394 }
9495
96+ /** The color of the progress-spinner. Can be primary, accent, or warn. */
97+ @Input ( )
98+ get color ( ) : string { return this . _color ; }
99+ set color ( value : string ) {
100+ this . _updateColor ( value ) ;
101+ }
102+
95103 /** Value of the progress circle. It is bound to the host as the attribute aria-valuenow. */
96- private _value : number ;
97104 @Input ( )
98105 @HostBinding ( 'attr.aria-valuenow' )
99106 get value ( ) {
@@ -128,14 +135,11 @@ export class MdProgressSpinner implements OnDestroy {
128135 }
129136 this . _mode = m ;
130137 }
131- private _mode : ProgressSpinnerMode = 'determinate' ;
132-
133- @Input ( ) color : 'primary' | 'accent' | 'warn' = 'primary' ;
134138
135139 constructor (
136- private _changeDetectorRef : ChangeDetectorRef ,
137140 private _ngZone : NgZone ,
138- private _elementRef : ElementRef
141+ private _elementRef : ElementRef ,
142+ private _renderer : Renderer
139143 ) { }
140144
141145
@@ -229,6 +233,23 @@ export class MdProgressSpinner implements OnDestroy {
229233 path . setAttribute ( 'd' , getSvgArc ( currentValue , rotation ) ) ;
230234 }
231235 }
236+
237+ /**
238+ * Updates the color of the progress-spinner by adding the new palette class to the element
239+ * and removing the old one.
240+ */
241+ private _updateColor ( newColor : string ) {
242+ this . _setElementColor ( this . _color , false ) ;
243+ this . _setElementColor ( newColor , true ) ;
244+ this . _color = newColor ;
245+ }
246+
247+ /** Sets the given palette class on the component element. */
248+ private _setElementColor ( color : string , isAdd : boolean ) {
249+ if ( color != null && color != '' ) {
250+ this . _renderer . setElementClass ( this . _elementRef . nativeElement , `md-${ color } ` , isAdd ) ;
251+ }
252+ }
232253}
233254
234255
@@ -245,12 +266,15 @@ export class MdProgressSpinner implements OnDestroy {
245266 'role' : 'progressbar' ,
246267 'mode' : 'indeterminate' ,
247268 } ,
269+ // Due to the class extending we need to explicitly say that the input exists.
270+ inputs : [ 'color' ] ,
248271 templateUrl : 'progress-spinner.html' ,
249272 styleUrls : [ 'progress-spinner.css' ] ,
250273} )
251274export class MdSpinner extends MdProgressSpinner implements OnDestroy {
252- constructor ( changeDetectorRef : ChangeDetectorRef , elementRef : ElementRef , ngZone : NgZone ) {
253- super ( changeDetectorRef , ngZone , elementRef ) ;
275+
276+ constructor ( elementRef : ElementRef , ngZone : NgZone , renderer : Renderer ) {
277+ super ( ngZone , elementRef , renderer ) ;
254278 this . mode = 'indeterminate' ;
255279 }
256280
0 commit comments