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