I have the following object named $scope.workflow
:
{
"name":"Demo #1",
"flow":[
{
"tasks":[
{
"name":"Task 1 Step 1",
"$$hashKey":"object:25"
},
{
"name":"Task 2 Step 1",
"$$hashKey":"object:93"
}
],
"$$hashKey":"object:21"
},
{
"tasks":[
{
"name":"Task 1 Step 2",
"$$hashKey":"object:29"
}
],
"$$hashKey":"object:22"
}
]
}
And I have the following template
<ul>
<li ng-repeat="data in workflow.flow" ng-init="$stepIndex = workflow.flow.indexOf(data)">
<div class="step_container">
<div class="step_header">{{ data.name }}</div>
<div class="step_content">
<div class="task_container" ng-repeat="task in workflow.flow[$stepIndex].tasks">
<div ng-click="editTask(data, task)">
<div class="header">{{task.name}}</div>
</div>
</div>
</div>
</div>
</li>
</ul>
When a task is clicked as per the template, editTask()
Brings up the following:
$scope.editTask = function(step, task) {
$scope.step_index = $scope.workflow.flow.indexOf(step_index);
$scope.task_index = $scope.workflow.flow[$scope.step_index].tasks.indexOf(task);
//code that opens up a popup model
}
The popup model as the following:
<div ng-click="deleteTask()">Delete me</div>
So along with my splice, I do a console.log to make sure it is selecting the correct object like so:
$scope.deleteTask = function() {
console.log($scope.workflow.flow[$scope.step_index].tasks[$scope.task_index]);
$scope.workflow.flow[$scope.step_index].tasks.splice($scope.task_index, 1);
}
The console.log confirms that I am selecting the right task but if I try to delete the last task it will delete the second to last on instead. And if I try to delete the last task after that, it won't delete any of them.
Does anyone know what I could be doing wrong? It makes no sense because the console.log is literally outputting what I want to delete every single time but the splice isn't working right.