how to delete (splice) an element from nested JSON using AngularJS
You could, among other things do the following:
$scope.remove = function (index, comments) {
delete $scope.comments[index]
}
Upon closer inspection, it would seem that you have a nested data structure there, which means you need two indexes: one for the phone and one for the comment within the phone data structure.
So what you would need is a method along the lines of:
$scope.remove = function (pIndex, cIndex) {
delete $scope.phones[pIndex].phone_comments[cIndex];
}
One other suggestion I'd put forth is that you should make phones a first-class citizen model and manipulate them through a Service.
Thanks to both of you. The first suggestion actually worked.
$scope.removeComment = function (pid, cid) {
$scope.phones[pid].phone_comments.splice(cid, 1);
};
and the call from the HTML was
<th><button ng-click="removeComment($parent.$index, $index)">Remove Comment</button>