1

I have the following HTML + AngularJS code:

    <table class="table table-hover">
      <thead>
        <tr>
          <th width="80%">Task</th>
          <th width="10%">Delete</th>
        </tr>
      </thead>
      <tbody>
        <tr ng-repeat="task in task_list track by $index">
          <td>{{task.title}}</td>
          <td>
            <button ng-click="delete_task($index)" class="btn btn-success btn-xs">Completed</button>
          </td>
        </tr>
      </tbody>
    </table>

This generate a list of task like in the following image:

View image

When I click on the "Complete" button I am sending an http request to server, and that part is working fine. What I am trying to achieve is, when I click on the button the button text should change to 'Please wait'.

How can I achieve this using AngularJS without using jQuery.

1
  • Can you post a sample of how the task_list looks like? Commented Jan 21, 2016 at 2:55

1 Answer 1

2

You can do something like this. The following code will change the status of button while submitting to submitting. Once complete it will change to completed and also disable the button.

Html

<tr ng-repeat="task in task_list track by $index">
  <td>{{task.title}}</td>
  <td>
    <button ng-disabled="task.disabled" ng-click="delete_task($index)" class="btn btn-success btn-xs">{{task.status ? task.status : 'complete'}}</button>
  </td>
</tr>

Javascript

  $scope.delete_task = function(index) {
    var task = $scope.task_list[index];

    task.status = 'submitting';

    $http.get('post.json').then(function(res) {
      task.status = 'completed';
      task.disabled = true;
    });
  };

Here is working plunkr

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

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.