0

I need to stop sending multiple requests, when user clicks many times on the form submit button. So the user can't send next request until the first response is receiving. In the meanwhile he can see the spinner animation instead of this button. When response is receiving, he can click and submit again.

Not sure how to start. The button has own component, and I would like to modify the code in one place. Not sure if I need to use interceptors, directives, or what? What do you think?

1
  • 2
    Change the [disabled] property from the button. Commented Jan 11, 2018 at 11:36

2 Answers 2

3

In the component's class create a boolean variable isBusy and set it to true in the onSubmit() method. When the result (or an error) comes back, set it back to false.

Bind the isBusy var to disabled property of the Submit button:

<button type="submit" [disabled]="isBusy">Submit</button>

Sign up to request clarification or add additional context in comments.

Comments

1

You can use the below mentioned package to manage the loader on a http request.

https://www.npmjs.com/package/angular2-busy

Hope this helps

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.