import { Component , OnInit } from '@angular/core' ; import { Consumer } from '../classes/consumer' ; import { ConsumerService } from '../services/consumer.service' ; import { ActivatedRoute , Params } from '@angular/router' ; import { Observable , interval } from 'rxjs' ; @ Component ( { selector : 'consumer_application' , templateUrl : '../../templates/consumer.html' , } ) export class ConsumerComponent implements OnInit { consumerName : string ; environmentName : string ; observableConsumer : Observable < Consumer > ; consumer : Consumer ; constructor ( private consumerService , private route ) { } ngOnInit ( ) { this . getParams ( ) ; this . observableConsumer = this . consumerService . consumer ; this . observableConsumer . subscribe ( consumer => { this . consumer = consumer ; } ) ; let startWindow = 0 ; let refresh = interval ( 2 * 1000 ) . subscribe ( x => { startWindow ++ ; this . consumerService . refreshData ( ) ; if ( startWindow === 5 ) { refresh . unsubscribe ( ) ; refresh = interval ( 10 * 1000 ) . subscribe ( t => { this . consumerService . refreshData ( ) ; } ) ; } } ) ; } getParams ( ) { this . route . queryParams . subscribe ( ( params ) => { this . consumerName = params [ 'consumer' ] ; this . environmentName = params [ 'environment' ] ; } ) ; } }