As a complement to Otto’s response, I suggest you use finally
instead of then
, because, if a failure occurs, the variable that indicates loading will be locked "forever".
I would do so:
<button ng-click="save()" ng-disabled="isProcessing">Save</button>
$scope.save = function(){
$scope.isProcessing = true;
$http.post('localhost', data)
.finally(function () {
$scope.isProcessing = false;
})
.then(function (response) {
$scope.resposta = response.data;
})
}
The finally
is always executed at the end of the request, regardless of whether it ended with failure or not.
Always try to post what you did together so there are no downvotes
– Otto
all right, I’m sorry.
– Brayan
+1 the question is good and the explanation dispenses with the placement of codes.
– Wallace Maxters
I take back what I said, after seeing your question. You should have put this information in the question before the AR answer.
– Wallace Maxters