这就是为什么我的总数不计算
<div ng-controller="MyHomeCNtrls">
<div id="CountdataWithinhTheDiv">
<table>
<tr>
<td>Id</td>
<td>Name</td>
<td>Quentity</td>
<td>Price</td>
<td>Total</td>
</tr>
<tr ng-repeat="pr in Prodt">
<td>{{pr.productId}}</td>
<td>{{pr.ProductName}}</td>
<td>{{pr.quantity}}</td>
<td>{{pr.Price}}</td>
<td>{{pr.Total}}</td>
<td>Total: {{ getTotal() }}</td>
</tr>
</table>
</div>
</div>
AngularCode 的服务 this.Gymser = function(){ var xx = $ http({url:'/ Home / Prodt',方法:'获取',参数:JSON.stringify(), content:{'content-type':'application / Json'}})return xx;}
控制器
function PropertyData() {
var xxx = Myservice.Gymser();
xxx.then(function (d) {
$scope.Prodt = d.data;
})
}
AngularCode For Counting
$scope.getTotal = function () {
var total = 0;for (var i = 0; i < $scope.Products.length; i++) {
var product = $scope.Products[i];total += (Product.price * Product.quantity);}return total;}
答案 0 :(得分:0)
我没有看到您的控制器具有名为getTotal()
您应该在控制器中定义
$scope.getTotal = function(type) {
var total = 0;
angular.forEach($scope.items, function(el) {
total += el[type];
});
return total;
};