Unsubscribe Observables in Angular

Unsubscribe Observables in Angular

I want to show you here how I personally unsubscribe observables that I manually subscribe without the async pipe.

export class DataTableExamplesComponent {

  private subs: Subscription[] = [];

  constructor(private myService: MyService) {
      const getDataSub = this.myService.getData$.subscribe((data) =>        console.log(data));
      this.subs.push(getDataSub);
  }

  public ngOnDestroy() {
    this.subs.forEach(s => s.unsubscribe());
  }

}