Why I can't remove item from array posts?
html tag for delete item
html tag
<span ng-click="remove($index)"> delete</span>
//AngularJS method where I try to delete item
blog.remove = function(index) {
blog.posts.splice(index, 1);
};
//Angular array posts
blog.posts = [{
"title": "Blog Post One",
"comments": [
{
"body":"Lorem ipsum dolor sit amet, consectetur adipisicing elit. ",
"author": "trollguy87"
}
]}];
Where can be problem?
removeis getting called on scope. But you're definition is on the blog itself. So, shouldn't it beblog.remove($index)? And, what is the$index? Coming from some sort ofrepeatI assumeng-repeatpart, it is currently hard to figure how you manage$scope/vmvar blog = $scope;because you call$scope.removebyng-click="remove()"