获取Angular JS中的所有购物车数量

时间:2016-02-19 17:12:16

标签: html angularjs

我想获得所有购物车数量,但我得到错误。可以帮帮我吗?有关详细信息,请Preview

for (var i = 0; i < length; i++) {
  value = list[i];
  if (predicate.call(thisArg, value, i, list)) {
    return value;
  }
}
return undefined;

1 个答案:

答案 0 :(得分:1)

在范围内创建方法

喜欢这个

  $scope.totalItem = function() {
    return $scope.cart.map(function(x) {
      return +x.count;
    }).reduce(function(a, b) {
      return a + b;
    }, 0);
  }

现在在视图中添加此方法

{{totalItem()}}

DEMO