Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 从列中分类的部分总额_Angularjs - Fatal编程技术网

Angularjs 从列中分类的部分总额

Angularjs 从列中分类的部分总额,angularjs,Angularjs,我尝试使用AngularJS做一个示例-下面是我从JSON数据中获得的ngRepeat输出: Gadgets - $45 Power Bill - $50 Gadgets - 45 Power Bill - 50 所以,我想获得电费账单的总金额以及100和90等小工具的总花费——我如何使用AngularJS从ngRepeat动态获取这些信息 感谢您的提示和帮助!提前谢谢 您可以编写一个控制器函数来获取总数,并在单击按钮时调用它。 //项目列表数组 $scope.items=[2,3,4];/

我尝试使用AngularJS做一个示例-下面是我从JSON数据中获得的ngRepeat输出:

Gadgets - $45
Power Bill - $50
Gadgets - 45
Power Bill - 50
所以,我想获得电费账单的总金额以及100和90等小工具的总花费——我如何使用AngularJS从ngRepeat动态获取这些信息


感谢您的提示和帮助!提前谢谢

您可以编写一个控制器函数来获取总数,并在单击按钮时调用它。

//项目列表数组
$scope.items=[2,3,4];//这可以由您获取的ur json数据替换

$scope.total = 0;
$scope.getTotal = function() { <br>

    for(var i=0; i< $scope.items.length; i++) { 

        $scope.total+= $scope.items[i];

        console.log($scope.total);
    }

}
$scope.total=0;
$scope.getTotal=function(){
对于(var i=0;i<$scope.items.length;i++){ $scope.total+=$scope.items[i]; log($scope.total); } }
//多姆

{{item}} 获取总计{{Total}

查看用于获得此结果的JSON数据和角度模板将非常有用。 <div ng-repeat="item in items">{{item}}</div> <div><button ng-click="getTotal()" value="get">Get Total</button>{{total}}</div> </code>