Prevent navigating away if live feed is on

This commit is contained in:
Chrystian Huot 2019-07-10 13:02:08 -04:00
parent 48df618d93
commit 8b299ef5d5
2 changed files with 11 additions and 3 deletions

View file

@ -22,8 +22,8 @@ import { AppSharedModule } from './shared/shared.module';
path: '**',
pathMatch: 'full',
redirectTo: '',
}
])
},
]),
],
})
export class AppModule { }

View file

@ -1,4 +1,4 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Component, HostListener, OnDestroy, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { RadioEvent } from './radio';
import { AppRadioService } from './radio.service';
@ -27,6 +27,14 @@ export class AppRadioComponent implements OnDestroy, OnInit {
this._unsubscribe();
}
@HostListener('window:beforeunload', ['$event'])
private _exitNotification(event: BeforeUnloadEvent): void {
if (this.appRadioService.live) {
event.preventDefault();
event.returnValue = false;
}
}
private _subscribe(): void {
this._subscriptions.push(
this.appRadioService.event.subscribe((event: RadioEvent) => {