I have a loader service from Angular University course:
@Injectable()
export class LoadingService {
  private loadingSubject = new BehaviorSubject<boolean>(false);
  loading$: Observable<boolean> = this.loadingSubject.asObservable();
  showLoaderUntilCompleted<T>(obs$: Observable<T>): Observable<T> {
    return of(null).pipe(
      tap(() => this.on()),
      concatMap(() => obs$),
      finalize(() => this.off())
    );
  }
  on() {
    this.loadingSubject.next(true);
  }
  off() {
    this.loadingSubject.next(false);
  }
}
And it's usage in a component:
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
  providers: [LoadingService]
})
export class AppComponent {
  loading$: Observable<boolean>;
  constructor(private loader: LoadingService) {
    this.loading$ = loader.loading$;
  }
  submit() {
    this.loader.showLoaderUntilCompleted(timer(1000)).subscribe();
  }
  submit2() {
    this.loader.showLoaderUntilCompleted(timer(1000)).subscribe();
  }
}
And the template:
<form (ngSubmit)="submit()">
  {{ loading$ | async }}
  <button type="submit">Submit</button>
</form>
<form (ngSubmit)="submit2()">
  {{ loading$ | async }}
  <button type="submit">Submit</button>
</form>
It works perfectly in a case when component has only one form, can someone suggest how can I reuse it with multiple forms on the page? The goal is to have different loader states for each form.
Link to stackblitz