seantrant
4/30/2019 - 2:54 PM

More observables subject boolean

//Service
import { Subject, Observable } from 'rxjs';

@Injectable()
export class DService {

  onCall: boolean = false;
  onCallSubject: Subject<any> = new Subject<any>();

  constructor() {

  }

  startCall() { //TODO dont use any
    console.log('start call request');
    this.onCall = true;
    this.onCallSubject.next( this.onCall );
  }

  completeCall() {  //TODO dont use any
    console.log('end call request');
    this.onCall = false;
    this.onCallSubject.next( this.onCall );
  }

  getOnCallStatus(): Observable<any> {
      return this.onCallSubject.asObservable();
  }

}


// component
import { Observable, Subject, Subscription } from 'rxjs/Rx';

export class DComponent implements OnDestroy {

  overlayActive: boolean = false;
  onCallSubscription: Subscription;

  constructor( private dService: DService) {
    this.onCallSubscription = this.dService.getOnCallStatus().subscribe(status => {
      console.log(status);
      this.overlayActive = status;
    });
  }

  ngOnDestroy() {
    this.onCallSubscription.unsubscribe();
  }