0

How do I display a spinner while I'm waiting for the data to be displayed?

Is there a way to place a custom tag (from spinner component) in the HTML template where I'm waiting for the data?

My project is based on Angular Drupal POC

My list of articles component looks like this:

search() {
    this.sub = this.nodeService.getNodes({ q: this.q })
      .subscribe(
        res => {
          this.nodes = this.filteredNodes = res;
          this.totalItems = this.nodes.length;
        }
    );
  }
0

2 Answers 2

2

ow do I display a spinner while I'm waiting for the data to be displayed?

Have a spinner component bound to some loading property on your controller e.g.

search() {
    this.loading = true;
    this.sub = this.nodeService.getNodes({ q: this.q })
      .subscribe(
        res => {
          this.loading = false;
          this.nodes = this.filteredNodes = res;
          this.totalItems = this.nodes.length;
        }
    );
  }
Sign up to request clarification or add additional context in comments.

Comments

1

Try something like this:

search() {
  this.isNodeLoading = true;
  this.sub = this.nodeService.getNodes({ q: this.q })
   .subscribe(
     res => {
        this.isNodeLoading = false;
        this.nodes = this.filteredNodes = res;
        this.totalItems = this.nodes.length;
     }
  );
}

and define initially isNodeLoading: boolean= false;

then use in template like this:

<div class="loader-inner ball-clip-rotate" *ngIf="isNodeLoading">
       <div></div>
</div>

Hope this will help you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.