1

I'm pretty new to Angular 2, I have a site created which calls services but need to add a loading gif for each page or service call. Does anyone know how I can implement something like this?

Thanks

1 Answer 1

5

On your HTML you can write a spinner like the following:

<span *ngIf="isLoading">Loading...</span>
<span *ngIf="!isLoading">Result</span>

Before loading the service, probably on component load, you will have something like this on your component:

isLoading: Boolean = true;

Call the service on that component, subscribe to it, then change that boolean to true after the subscription has completed.

myService.subscribe(
  result => {
     // your other stuff here.
     isLoading = false;
  },
  error => {
     isLoading = false;
  }
Sign up to request clarification or add additional context in comments.

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.