Created
October 26, 2018 18:20
-
-
Save partharanjan/1655e5807a4080f9c23496f24e1fd18e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, OnDestroy } from '@angular/core'; | |
import { Subscription, interval } from 'rxjs'; | |
@Component({ | |
selector: 'ngx-color-spinner', | |
template: `<mat-spinner [color]="_color"></mat-spinner>`, | |
styles: [] | |
}) | |
export class NgxColorSpinnerComponent implements OnInit, OnDestroy { | |
intervalSubscription: Subscription; | |
_color: String; | |
colors: String[] = ['primary', 'accent', 'warn']; | |
constructor() { } | |
ngOnInit() { | |
this._color = this.colors[0]; | |
const source = interval(1000); | |
let index = 0; | |
const totalLength = this.colors.length; | |
this.intervalSubscription = source.subscribe(val => { | |
if (index == totalLength) { | |
index = 0; | |
} | |
this._color = this.colors[index]; | |
index++; | |
}); | |
} | |
ngOnDestroy() { | |
if (this.intervalSubscription) { | |
this.intervalSubscription.unsubscribe(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment