title: Does async pipe subscriptions still unsubscribe for Ionic Routing?
body: <p><strong>BACKGROUND:</strong> I'm currently working on a mobile app that uses Promises and I'm exploring RxJS' Observables to replace all existing promise API calls.
  My understanding for async pipe is that it automatically unsubscribes when the <code>ngOnDestroy</code> is triggered. Since I am using <a href="https://ionicframework.com/docs/angular/lifecycle" rel="nofollow noreferrer">Ionic Routing</a> it does not trigger the <code>ngOnDestroy</code> it can only trigger <code>ionViewWillLeave</code> once I navigated to other page.</p>
  <p><strong>CODE:</strong>
  I implemented an async pipe in my html template that looks like this:</p>
  <pre><code> &lt;ng-container *ngIf=&quot;accounts$ | async as accounts; else loadingData&quot;&gt;
    &lt;app-account-card *ngFor=&quot;let account of accounts&quot; [account]=&quot;account&quot;&gt;&lt;/app-account-card&gt;
  &lt;/ng-container&gt;
  
  &lt;!-- SKELETON --&gt;
  &lt;ng-template #loadingData&gt;
    &lt;app-skeleton-account-card&gt;&lt;/app-skeleton-account-card&gt;
  &lt;/ng-template&gt;
  </code></pre>
  <p>I have an <code>account.service.ts</code> that returns an <code>Observable&lt;Account[]&gt;</code>:</p>
  <pre><code>getAccountsObserver(): Observable&lt;Account[]&gt; {
  try {
          return from(this.getSessionID()).pipe(
              switchMap(sessionId =&gt; this.http.get&lt;Account[]&gt;(`${URLS.accounts}${ENDPOINTS.accBalance}${sessionId}`))
          );
      } catch (e) {
          return null;
      }
  }
  </code></pre>
  <p>For my <code>account.component</code> I simply declared a variable <code>accounts$</code>:</p>
  <pre><code>accounts$: Observable&lt;Account[]&gt;;
  
    constructor(
      private accountProvider: AccountProvider
    ) {}
  
    ngOnInit() {
      this.accounts$ = this.accountProvider.getAccountsObserver();
    }
  </code></pre>
  <p><strong>QUESTION:</strong> Does the Async Pipe still unsubscribes? If no, how can I unsubscribe to it? Is Async Pipe still a best way to display a data from the API or do I need to find a different approach in my case?</p>