title: Angular 9 and angular material MatDialog "error this.dialog is undefined"
body: <p>In my angular application, I try to catch and show error return by the back.
  The calls to the back are done in a dedicated service file (quick-list.service.ts)
  example call to the back :</p>
  <pre><code>getSeries(): Observable&lt;Object&gt; {
      return this.httpClient.get('http://localhost:8080/serieselk/liste').pipe(
        catchError(this.handleError)
      ); 
  }
  </code></pre>
  <p>In this same file I have a method (handleError)to catch the error:</p>
  <pre><code>private handleError(error: HttpErrorResponse) {
      if (error.error instanceof ErrorEvent) {
        // A client-side or network error occurred. Handle it accordingly.
        console.error('An error occurred:', error.error.message);
      } else {
        // The backend returned an unsuccessful response code.
        // The response body may contain clues as to what went wrong,
        console.error(
          `Backend returned code ${error.status}, ` +
          `body was: ${error.error.message}`);
      }
      //show error to user in a standard alert
      alert(&quot;test &quot;+error.error.message);
      //try to show the error in a MatDialog box to replace the ugly default alert...
      var confdata: Confirmdiagdata = {boxtitre : &quot;Erreur &quot;+error.status, texte:error.error.message};
      this.dialog.open(ConfirmdiagComponent, { //This line return the &quot;this.dialog is undefined&quot; error
        width: '25%',
        data: confdata
      });
      // return an observable with a user-facing error message
      return throwError(
        'Something bad happened; please try again later.');
  }
  </code></pre>
  <p>With this code, I have an &quot;this.dialog is undefined&quot; error and the matDialog box do not show up
  I use the same code for other MatDialog box in my application and it work fine.</p>
  <p>In this case, I try to open the dialog in an &quot;Injectable service&quot; (quick-list.service.ts) and in the other case (where it's work) I do it in &quot;component&quot; (seriedetails.component.ts for example)</p>
  <p>So my question, is it possible to use MatDialog box here ? and how ?</p>
  <p>quick-list.service.ts :</p>
  <pre><code>import { Injectable } from '@angular/core';
  import { HttpClient, HttpHeaders, HttpClientModule, HttpErrorResponse } from '@angular/common/http';
  import { Observable, throwError } from 'rxjs';
  import { catchError } from 'rxjs/operators';
  import { SeriestableItem} from '../seriestable/seriestable-datasource';
  import { Confirmdiagdata, ConfirmdiagComponent } from '../confirmdiag/confirmdiag.component';
  import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material/dialog';
  
  @Injectable({
    providedIn: 'root'
  })
  
  export class QuickListService{
  
    constructor(private httpClient: HttpClient, public dialog: MatDialog) { }
  
    [...]
    //some other methodes...
    [...]
  
    getSeries(): Observable&lt;Object&gt; {
      return this.httpClient.get('http://localhost:8080/serieselk/liste').pipe(
        catchError(this.handleError)
      );
    }
    
    private handleError(error: HttpErrorResponse) {
      if (error.error instanceof ErrorEvent) {
        // A client-side or network error occurred. Handle it accordingly.
        console.error('An error occurred:', error.error.message);
      } else {
        // The backend returned an unsuccessful response code.
        // The response body may contain clues as to what went wrong,
        console.error(
          `Backend returned code ${error.status}, ` +
          `body was: ${error.error.message}`);
      }
      //this.openDialog(error);
      alert(&quot;test &quot;+error.error.message);
      var confdata: Confirmdiagdata = {boxtitre : &quot;Erreur &quot;+error.status, texte:error.error.message};
      this.dialog.open(ConfirmdiagComponent, {
        width: '25%',
        data: confdata
      });
      
      // return an observable with a user-facing error message
      return throwError(
        'Something bad happened; please try again later.');
    }
  
  }
  </code></pre>