2

how to disable submit button in angularJs to prevent duplicate response from service.

I am new to angularJs and also this should be supported in IE 8.

2
  • what do you mean by duplicate response? are you trying to block multiple form submissions? Commented Nov 13, 2014 at 19:35
  • duplicate response is if I call a GET service, upon clicking the submit multiple number of times I call GET service multiple number of times and hence I get duplicate results. So, I want to disable the submit button after a single click until it loads the response. Commented Nov 13, 2014 at 19:40

1 Answer 1

4

The following approach works for me.

View:

<button ng-disabled="isBusy" ng-click="buttonClick()">Load</button>

Controller:

$scope.buttonClick = function () {
    $scope.isBusy = true;
    service.getData()
    .success(function (data) {
        // Use the data
    })
    .error(function (data, status, headers, config) {
        // Log the error
    })
    .finally(function () {
        $scope.isBusy = false;
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Would this also work without using ng-click directive, but specifying <button type="submit" ng-disabled="..."> ? In this case the button look visually disabled, but triggers "submit" events on my controller.

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.