0

I have a situation where I want to disable the button for a few seconds when clicked. Here is the code for button:

<button uib-popover="Create TO" popover-trigger="mouseenter" data-ng-click="createTransportOrder(item.confirmed_price_id)" data-ng-disabled="item.transport_order_id || !item.confirmed_price_id" class="btn btn-info btn-xs">
                            <i class="fa fa-truck"></i>
                        </button>

And here is the createTransportOrder method:

$scope.createTransportOrder = function (priceResponseId) {
            var priceResponseIds = [priceResponseId];
            PriceRequestsModel.createTransportOrdersByIds(priceResponseIds).then(
                function (response) {
                    $scope.messages = response.messages;
                    updateSelectedPriceRequests();
                    getPriceRequests();
                },
                function (response) {
                    $scope.messages = response.messages;
                }
            )
        };

I have tried a couple of things but in vain. How can I do this?

2
  • for how much time you want it disabled? Commented Apr 21, 2020 at 11:43
  • for just three seconds Commented Apr 21, 2020 at 11:44

1 Answer 1

0

You can add setTimeout at the end of createTransportOrder

 this.button.nativeElement.disabled = true;
    setTimeout(function(){
      this.button.nativeElement.disabled = false;
    },5000);

Add #mybutton to your button <button (click)="yourclick()" #mybutton>Your button</button>

add variable @ViewChild('mybutton') button; to your component

Stackbliz demo code: https://stackblitz.com/edit/angular-disable-5second

With angular 1.4 you can change to

Set an id to your button as <button id="mybutton">

Add these code to below of click function.

document.getElementById('mybutton').disabled = true;
    setTimeout(function(){
      document.getElementById('mybutton').disabled = false;
    },5000);
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for the answer. My angular version is 1.4 and the answer you gave probably isn't for my version. I have updated the heading of the question.
This works fine but my problem is that I have to list data where every row contains that one button I want to disable after click. So id wont work. Neither would class as it'll pick the first occurrence of the button. is there anyway I can get the current button in the createTransportOrder method?

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.