我是Angular的新手,并且有一个关于ng-bind的基本问题,但在文档中找不到答案。我的场景基于O'Reily Angular.js书中的购物车应用程序,但似乎无法使ng-bind工作。
期望的输出:我需要修改我的控制器函数,以便可以在“Grand Total” span中显示更新后的$scope.items数组元素。
以下是该函数:
function CartController($scope) {
$scope.items = [
{title: 'Software', quantity: 1, price: 1399.95},
{title: 'Data Package (1TB)', quantity: 1, price: 719.95},
{title: 'Consulting (per hr.)', quantity: 1, price: 75.00}
];
$scope.remove = function(index) {
$scope.items.splice(index, 1);
},
$scope.reset = function(index) {
$scope.items = [
{title: 'Software', quantity: 0, price: 1399.95},
{title: 'Data Package (1TB)', quantity: 0, price: 719.95},
{title: 'Consulting (per hr.)', quantity: 0, price: 75.00}
];
};
}
grandTotal()
更改为将三个值写入作用域 ($scope.baseTotal=X; $scope.vat22=Y; $scope.total=Z;
),然后使用$watch
或$watchCollection
监视项目数组中的更改并在集合更改时调用grandTotal()
。 - Langdon