我在ng-repeat中有一个表达式,用于计算表格行中的各种输入并返回总薪酬,如下所示:
控制器
App.controller 'calcPayCtrl', ($scope, $filter, Api, employments) ->
active_employments = $filter('filter')(employments, {status: 'active'})
$scope.employments = active_employments
angular.forEach $scope.employments, (employment) ->
payslip = {employment_id: employment.id}
employment.payslip = payslip
查看
<td>
<input ng-model="row.payslip.hours_worked">
<input ng-model="row.payslip.overtime_hours_worked">
</td>
<td>
<h5>Gross Pay</h5>: {{ ((row.payslip.hours_worked*row.hourly_rate) || 0) + ((row.payslip.overtime_hours_worked*row.overtime_multiple) || 0 | currency: "" }}
</td>
表达式按预期工作。
现在我想把总薪水的结果分配给$ scope模型,这样我就可以将它保存到Rails Api中了
row.gross_pay = gross_pay
如何将表达式的结果分配给模型?
答案 0 :(得分:0)
这是我如何设法保存计算结果。
$scope.saveAll = ->
payslips = []
angular.forEach $scope.employments, (employment) ->
payslip = employment.payslip
payslip.gross_pay = ..........****calculation****.......
payslips.push(payslip)
Api.Batch.save(payslips)