Increment A Variable In AngularJS Template

前端 未结 3 1250
广开言路
广开言路 2020-12-16 16:19

I\'ll preface this by saying I am very new to AngularJS so forgive me if my mindset is far off base. I am writing a very simple single page reporting app using AngularJS, th

3条回答
  •  [愿得一人]
    2020-12-16 16:31

    I'm not sure I totally understand the question, but are just needing to display the total number in the object you're iterating over? Just set $scope.total to the length of your array (bar in your example above). So, $scope.total = $scope.bar.length;

    If you're wanting the total of all the foo.baz properties, you just need to calculate that in your controller.

    $scope.total = 0;
    angular.forEach($scope.bar, function(foo) {
        $scope.total += foo.baz;
    });
    

提交回复
热议问题