Reputation: 162
We have the below HTML code which uses Angular.js,
<div ng-if="$scope.IsResult == false">
<label style="font-weight: bold;"> Count : {{student.length }}</label>
</div>
Here the student is the JSON array returned and contains few records with student.Active=false.
Currently its displaying all students count. We need to display the length only for active students i.e student.Active=true. How can I achieve this in Angular.js.
Please advise.
Upvotes: 0
Views: 253
Reputation: 28059
You would be best putting a function in your controller which calculates this and calling that from your view.
So in your controller:
$scope.countInactiveStudents = function(student){
var count = 0;
for(var i = 0; i < student.length; i++){
if(!student[i].Active){
count++;
}
}
return count;
}
And in your view:
<label style="font-weight: bold;"> Count : {{countInactiveStudents(student) }}</label>
Upvotes: 1