0

When I press accept button task should be updated with new value which I wrote in input.Sad thing it doesnt work like I want.Do i need to add id`s to array with objects?

or maybe there is some good method to send a object to function.Here`s the code:

<tbody>
    <tr ng-repeat="task in tasks">
        <td>
            <button class="btn btn-danger" ng-click="deleteTask(task)">Delete</button>
            <!--  $index-->
        </td>
        <td>{{task.taskName}}</td>
        <td>
            <input type="checkbox" ng-model="statusCheck"> </td>
        <td style="{{setStyleToTd(statusCheck)}}">{{statusChecker(statusCheck)}}</td>
        <td>
            <button class="btn btn-primary" ng-click="editTask(task)">Edit</button>
        </td>
    </tr>
</tbody>
</table>
</div>
<div class="col-md-offset-8 edit-box" ng-show="editBoxShow">
    <form action="" class="form-inline">
        <div class="form-group">
            <lable>Edit task here:</lable>
            <div class="input-group">
                <input type="text" class="form-control" ng-model="editTaskInput"> </div>
            <button type="button" class="btn btn-success" ng-click="acceptEdit()">Accept</button>
        </div>
    </form>
</div> 

$scope.editTask = function(taskToEdit) {
    $scope.editBoxShow = true;
    $scope.editTaskInput = taskToEdit.taskName;
}
$scope.acceptEdit = function() {
    $scope.editBoxShow = false;
    $scope.taskToEdit = $scope.editTaskInput;
}

enter image description here

1 Answer 1

1

You can capture the index of your table data while clicking edit button and then update the table data by using this index in acceptEdit function.

$scope.editTask = function (taskToEdit) {
    $scope.selectedIndex=$scope.tasks.indexOf(taskToEdit);
    $scope.editBoxShow = true;
    $scope.editTaskInput = taskToEdit.taskName;
}

 $scope.acceptEdit = function () {
    $scope.editBoxShow = false;
    $scope.tasks[$scope.selectedIndex].taskName=$scope.editTaskInput;
}
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.