由于发票行计算的复杂性,我需要创建发票行将是独立控制器的发票。
我的问题是:如何定义 InvoiceLine 控制器数组并使用 ng-repeat 绑定它们?
我是 Angular 的新手,在淘汰赛中我是这样做的:http: //knockoutjs.com/examples/cartEditor.html
<script type="text/javascript">
var invoiceTest = angular.module("InvoiceTest", []);
invoiceTest.controller(
"InvoiceHead",
function ($scope) {
// how to define ? $scope.InvoiceLine = [array of controllers]
$scope.VAT = 0.17;
$scope.TotalNoVat = ???; // Neet To Calc the Sum of $scope.InvoiceLine.TotalCost
$scope.TotalInvluceVAT = function() {
return ($scope.TotalNoVat * (1+ $scope.VAT)).toFixed(2);
};
}
);
invoiceTest.controller("InvoiceLine",
function ($scope) {
$scope.Description = "";
$scope.Quantity = 1;
$scope.Cost = 0;
$scope.TotalCost = function() {
return ($scope.Quantity * $scope.Cost).toFixed(2);
};
//more complex calculation and ajax ...
}
);
</script>