Trying to create a function that will remove the selected checkbox items from the array but can't seem to figure it out. I have tried using splice and .pop() but it just won't remove the items I select. I think the best way would be to use an if statement but I do not know how to write it so that it shows true or false. Please help!!!
JS:
.controller('toDoCtrl', function($scope, toDoFactory){ //set $scope variables $scope.tasks = toDoFactory.tasks; $scope.removeTasks = toDoFactory.removeTasks; }) .factory('toDoFactory', ['$http', function($http){ var toDo = { tasks: [], removeTasks: function(selectedTask){ angular.forEach(toDo.tasks, function(value, selectedTask){ var i = toDo.tasks.indexOf(value); toDo.tasks.splice(toDo.tasks.indexOf(i), 1); }); } }; return toDo; }])
HTML:
<button ng-click="removeTasks()">Remove</button>
value
you should findindexOf(selectedTask)
and you are not passingselectedTask
from calling offactory
method.