您可以将以下方法添加到控制器中。
selectedStudentsCount您范围内的变量将保留所有 选定学生的
数量(其中
isSelected设置为
true)。
功能计数 选定的用户 中
angular.forEach只有将被执行
students不为空。否则将返回 空
students变量。
selectedStudentsCount``0
$scope.selectedStudentsCount = function() { var count = 0; angular.forEach($scope.students, function(student){ count += student.isSelected ? 1 : 0; }); return count; }请注意,这
selectedStudentsCount是一个函数,因此必须
()在模板中使用来调用,例如
<h2>Total selected students: {{selectedStudentsCount()}}</h2>


