5

I have in AngularJS a list with multiple entries and for each entry a button. When clicking the button, the application will do some stuff and after that was successful, the button should be disabled.

The interesting part in my template look like this:

<li ng-repeat="item in items">
  <span>{{item}}</span>
  <button ng-click="doSomeStuff(item)">Request</button>
</li>

I already tried to use the ng-if directive, but then of course every button will disappear.

Previously, I thought about a solution in raw Javascript or jQuery, because it is very easy just to modify the button by its id. But is there a solution provided by AngularJS?

1
  • Did my answer help you? Commented Nov 11, 2015 at 16:03

1 Answer 1

4

Use ng-disabled as follows:

<li ng-repeat="item in items">
  <span>item</span>
  <button ng-click="doSomeStuff(item)" ng-disabled="item.disabled">Request</button>
</li>

Controller:

$scope.doSomeStuff = function(item) {
    //do operations and finally set disabled to true for that button
    item.disabled = true;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Ah, I see. Looks like a good solution, although I merge model data with ui. But for me it works. Thanks!
You're welcome! Please accept the answer if you found it correct... :)
How do I do that? I'm quite new to StackOverflow :D
Haha...Click the tick underneath the down arrow on the left.
Done. Thanks again :)

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.