我有一个待办事项列表,我希望当我单击“标记的标记”按钮时,所有选中的元素都会被标记。
这是我的代码 index.html
<!DOCTYPE html>
<html>
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<style>
.strike {
text-decoration: line-through;
}
</style>
</head>
<body ng-app="myApp" ng-controller="todoCtrl">
<h2>My Todo List</h2>
<div ng-repeat="x in todoList">
<input type="checkbox" ng-model="x.done"><span ng-class="" ng-bind="x.todoText"></span>
</div>
<p>
<button ng-click="strike()">Strike marked</button>
</p>
<script src="myNoteCtrl.js"></script>
</body>
</html>
这是 myNoteCtrl.js
var app = angular.module('myApp', []);
app.controller('todoCtrl', function($scope) {
$scope.todoList = [{todoText:'Clean House', done:false},{todoText:'Clean House2', done:false}];
$scope.strike = function() {
var oldList = $scope.todoList;
angular.forEach(oldList, function(x) {
if (!x.done) x.todoText.class="strike";
});
};
});