import {Component, OnDestroy, OnInit} from '@angular/core'; import {StudentViewService} from '../services/student-view.service'; import {takeWhile} from 'rxjs/operators'; import {LecturerViewService} from '../services/lecturer-view.service'; @Component({ selector: 'app-lecturer-root', templateUrl: './lecturer-root.component.html', styleUrls: ['./lecturer-root.component.css'] }) export class LecturerRootComponent implements OnInit, OnDestroy { public onDashboard: Boolean; public onClassView: Boolean; public onCompletedView: Boolean; public onSubmissionView: Boolean; public isAlive = true; constructor(private lecturerViewService: LecturerViewService) { } ngOnInit(): void { this.lecturerViewService.onDashboard$.subscribe(flag => { this.onDashboard = flag; }).add(takeWhile(() => this.isAlive)); this.onDashboard = true; this.onClassView = false; this.onCompletedView = false; this.onSubmissionView = false; this.lecturerViewService.changeToDashboard(this.onDashboard); } ngOnDestroy(): void { this.isAlive = false; } }