title: TypeError: Cannot read property 'back' of undefined
body: <p>This is my component.html</p>
  
  <pre><code>&lt;button type="button"
      (click)="save()"&gt;Save&lt;/button&gt;
  </code></pre>
  
  <p>This is my component.ts </p>
  
  <pre><code>private heroService: HeroService;
  private location: Location;
  constructor(heroService: HeroService) {
      this.heroService = heroService;
  }
  ngOnInit() { }
  
  @Input("hero") hero: Hero;
  
  public save(): void {
      this.heroService.updateHero(this.hero)
          .subscribe(()=&gt; this.goBack());
  }
  goBack(): void {
      this.location.back();
  }
  </code></pre>
  
  <p>This is my service.ts</p>
  
  <pre><code>private heroesUrl = 'api/heroes'; 
  updateHero(hero: Hero): Observable&lt;any&gt; {
      return this.http.put(this.heroesUrl, hero, httpOptions).pipe(
          tap(_ =&gt; this.log(`updated hero id=${hero.id}`)),
          catchError(this.handleError&lt;any&gt;('updateHero'))
      );
  }
  </code></pre>
  
  <p>When i click save in my application i am getting the below error while location.back(); is called. </p>
  
  <p><a href="https://i.stack.imgur.com/S6F3V.png" rel="nofollow noreferrer">https://i.stack.imgur.com/S6F3V.png</a></p>