title: Recreating a component when data changes
body: <p>Ok so there seems to be a lot of answers to this question but I haven't been able to comprehend what I should do.</p>
  
  <p>I currently have a child component that is being created when someone clicks a play button from another child component. This is happening through a service which shares the data with my parent and then the parent passes the data and creates my child audio-player component. The problem I'm having is if the user navigates to another page and clicks to play the audio on that page the old audio still persists and the new audio doesn't start. </p>
  
  <p>Is there a lifecycle hook or a method I could use to destroy my old audio component and create a new audio onclick?</p>
  
  <p>Info Box - Where the initial activation happens when play button is clicked.</p>
  
  <pre><code>export class InfoBoxComponent implements OnInit {
    ...
  
    activateAudioPlayer(session) {
      this.newAudioService.newAudio(session)
    }
  }
  </code></pre>
  
  <p>New Audio Service</p>
  
  <pre><code>export class NewAudioService {
    newActiveAudioSource: Subject&lt;string&gt; = new Subject&lt;string&gt;();
  
    newAudio(session) {
      this.newActiveAudioSource.next(session);
    }
  
    newActiveAudio$ = this.newActiveAudioSource.asObservable();
  }
  </code></pre>
  
  <p>Frontend Component - Parent Component of Info Box and Audio Player</p>
  
  <pre><code>@Component({ 
     template: `&lt;audio-player *ngIf='newActiveAudio' [newActiveAudio]='newActiveAudio'&gt;&lt;/audio-player&gt;`,
  })
  
  export class FrontendComponent implements OnInit {
  
    ...
  
    ngOnInit() {
      this.sub = this.newAudioService.newActiveAudio$.subscribe(
        newActiveAudio =&gt; {
          this.newActiveAudio = newActiveAudio;
        });
    }
  
    ngOnDestroy() {
      // prevent memory leak when component destroyed
      this.sub.unsubscribe();
    }
  }
  </code></pre>