import { Component , OnInit , OnDestroy } from '@angular/core' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { Subscription } from 'rxjs' ; import { GeoService , LocationError } from '@shared/geo.service' ; import { AbstractForm } from '../abstract-form.component' ; @ Component ( { selector : 'tell-us-form-location' , styleUrls : [ './location.component.scss' ] , templateUrl : './location.component.html' } ) export class LocationComponent extends AbstractForm implements OnInit , OnDestroy { subscription = new Subscription ( ) ; constructor ( public geoService , public snackBar ) { super ( ) ; } /**
     * Unsubscribe from the GeoService.error$ observable
     */ ngOnDestroy ( ) { this . subscription . unsubscribe ( ) ; } /**
     * Subscribe to GeoService.error$ and display error in a SnackBar component
     */ ngOnInit ( ) { this . subscription = this . geoService . error$ . subscribe ( ( locationError ) => { if ( locationError ) { this . openSnackBar ( locationError . message , 'close' ) ; } } ) ; } param message param action param length openSnackBar ( message , action = null , length = 3000 ) { this . snackBar . open ( message , action , { duration : length } ) ; } }