How to show a loading spinner while waiting on an observable getting data from a service in Angular

前端 未结 6 1419
情书的邮戳
情书的邮戳 2020-11-27 08:35

I have set up an observable service that helps me persist data, but I need a way to show a loading spinner while the data is waiting to come from the observable.

My

6条回答
  •  独厮守ぢ
    2020-11-27 09:01

    change the below line

    async getData() {
        this.organisations$ = this.organisationsService.getList();
      }
    

    to

    async getData() {
       this.organisations$ = this.organisationsService.getList();
       this.organisations$.subscribe((data) => 
         this.loading = false;
       );
      }
    

    this should work because this is the observable you are waiting for completion, not the getData method

提交回复
热议问题