AngularJS: Count Filtered Items

前端 未结 4 1728
醉话见心
醉话见心 2020-12-31 03:31

I am showing subsets of a list if a checkbox is checked. I would like to replace the X next to the checkbox with the count of the list matching the selection criteria. I hav

4条回答
  •  無奈伤痛
    2020-12-31 04:04

    To find the count objects, I use .length in the .html template.

    Here's my controller:

    conciergeControllers.controller('GuestMsgPreviewCtrl', ['$scope', 'GuestMessages',
        function($scope, GuestMessages) {
        $scope.guests = GuestMessages.query();
    }]);
    

    And template (each guest object has a messages attribute that is an array object, so .length returns the number of nested message objects:

    • [[ guest.messages.length ]]

提交回复
热议问题