有人可以告知以下为什么不起作用。
控制器:
(function () {
'use strict';
angular
.module("shop")
.controller("CartSummaryController", CartSummaryController);
function CartSummaryController($scope, cart) {
$scope.cartData = cart.getProducts();
console.log($scope.cartData);
$scope.total = function () {
var total = 0;
for (var i = 0; i < $scope.cartData.length; i++) {
total += ($scope.cartData[i].price * $scope.cartData[i].count);
}
return total;
}
$scope.remove = function (id) {
cart.removeProduct(id);
}
}
})();
HTML:
<div ng-show="cartData.length == 0">
There are no products in your shopping cart.
</div>
<div ng-hide="cartData.length == 0">
<table class="table">
<thead>
<tr>
<th>Quantity</th>
<th>Item</th>
<th class="text-right">Price</th>
<th class="text-right">Subtotal</th>
</tr>
</thead>
</table>
<tbody>
<tr ng-repeat="item in cartData">
<td>{{item.count}}</td>
<td>{{item.name}}</td>
<td>{{item.price | currency}}</td>
<td>blah</td>
</tr>
</tbody>
</div>
打印到控制台的对象:
对象 计数 : 1 ID : “1” 名称 : “第1项” 价钱 : “100.00”
此外,有没有办法调试ng-repeat?
答案 0 :(得分:2)
标签</table>
应位于标签</tbody>