Angular - DialogRef - Unsubscribe - Do I need to unsubscribe from afterClosed? : <p>I got asked by one of my colleagues if we need to unsubscribe from the afterClosed() Observable of a Dialog.</p>

<p>We are using the takeUntil pattern to unsubscribe from all Observables on ngOnDestroy().</p>

<pre><code>this.backEvent = fromEvent(window, 'popstate')
    .pipe(
        takeUntil(this.destroy$)
    )
    .subscribe(
        () =&gt; {
            this.navigationService.backClicked = true;
            this.navigationService.navigateBackToDirectoryCenter();
        }
    );
</code></pre>

<p>ngOnDestroy()</p>

<pre><code>ngOnDestroy() {
    this.destroy$.next();
    this.destroy$.complete();
}
</code></pre>

<p>So is it necessary to unsubscribe from afterClosed() Observable?</p>

<pre><code>dialogRef.afterClosed().subscribe(
    (data) =&gt; {
            console.log(data);
        }
    },
);
</code></pre>

<p>or?</p>

<pre><code>dialogRef.afterClosed()
    .pipe(
        takeUntil(this.destroy$)
    )
    .subscribe(
        (data) =&gt; {
            console.log(data);
        },
    );
</code></pre>
