The function toggleIntervention is called every time a check-box is checked/unchecked. It should push an object to array or remove it from the array depending if its checked/unchecked.
I am using indexOf to check if the object exist in the array, however the index is always -1 even if the object exists in the array. What am I missing?
$scope.selectedInterventions=[];
$scope.toggleIntervention = function(inputIntervention) {
var intervention = {
cptCode:inputIntervention.service,
description:inputIntervention.description,
notes:"intervention notes",
targetDate:"11/11/2014",
resolutionDate:"11/11/2014"
};
// The index always -1 even if the object exists in the array of selectedInterventions
var idx = $scope.selectedInterventions.indexOf(intervention);
if (idx > -1) {
$scope.selectedInterventions.splice(idx, 1);
} else {
$scope.selectedInterventions.push(intervention);
}
};