I have li item that repeat, according to $scope.items list. In each li I have a checkbox. What I want to do is to catch the change event of this checkbox and do my work there. Executed in $scope.change function.
When my work done, I want to remove the row of the checked checkbox.
My code so far:
<!doctype html>
<html>
<head>
<script src="http://code.angularjs.org/1.2.3/angular.min.js"></script>
<script>
var app = angular.module('myapp', []);
app.controller('mainController', function($scope) {
$scope.items = ["item1", "item2", "item3"];
$scope.change = function() {
// My work here.
// ...
// Work is done. remove the caller checkbox.
this.parent.remove(); // <--- BOOM.
}
});
</script>
</head>
<body ng-app="myapp">
<div ng-controller="mainController">
<ul>
<li ng-repeat="item in items">
<input type="checkbox" ng-model="checked" ng-change="change()">
</li>
</ul>
</div>
</body>
</html>
Live version is here: http://plnkr.co/edit/05IBKp6aVoj1SqFNi5JJ
My problem is in this code-line:
this.parent.remove(); // <--- BOOM.
My target is to remove the parent li.
Questions:
- How this can be done right?
- When I using the
thiskeyword (in controller.change function), is this something that I can use with JQuery syntax? Something like$(this).parent().remove();?