【发布时间】:2014-01-10 17:29:16
【问题描述】:
我对 angularFire 0.5.0 越来越失望,因为再也无法正常工作了。在您的帮助下我能够修复单个项目的删除后,我遇到了另一个问题。
每件商品都包含日期、描述和价格。在更新之前,我能够计算所有价格的总和并将其返回到页面上。现在它只是说 NaN 或 Null。我已经在尝试找出原因,但计算中的两个值(earning.price、$scope.totalEarning)都是数字。我不明白。新的角火有什么作用吗?一段时间以来,我一直在尝试修复它,但无法解决。如果有人能弄清楚,我真的会。可能我只是没有看到它,这是一个非常愚蠢的问题。
在 plunkr 上查看:http://embed.plnkr.co/jb1iWOcjcm0alFchmzOH/preview
代码如下:
$scope.addEarning = function() {
$scope.earnings.$add({date:$scope.FormEarningDate, description:$scope.FormEarningDescription, price:$scope.FormEarningPrice});
$scope.FormEarningDate = '';
$scope.FormEarningDescription = '';
$scope.FormEarningPrice = '';
$scope.updateEarning();
}
$scope.updateEarning = function() {
$scope.totalEarning = 0;
angular.forEach($scope.earnings, function (earning) {
price = parseFloat(earning.price)
$scope.totalEarning += price;
$log.log(typeof $scope.totalEarning);
})
$scope.totalBalance = $scope.totalEarning - $scope.totalCost;
}
还有html:
<form for="Profit" class="form-inline" style="margin-bottom: 20px" ng-submit="addEarning()">
<div class="form-group">
<div class="col-sm-3">
<input type="date" name="idate" ng-model="FormEarningDate" class="form-control" id="idate" placeholder="Date">
</div>
<div class="col-sm-5">
<input type="text" name="idesc" ng-model="FormEarningDescription" required class="form-control" id="idesc" placeholder="Description">
</div>
<div class="col-sm-2">
<input type="text" name="iprice" ng-model="FormEarningPrice" required class="form-control" id="iprice" placeholder="Amount">
</div>
</div>
<tr ng-repeat="earning in earnings | orderByPriority | orderBy : 'date'">
<td>{{earning.date}}</td>
<td>{{earning.description}}</td>
<td>{{earning.price}} €</td>
<td><button class="btn btn-danger" ng-click="earnings.$remove(earning.$id)">Löschen</button></td>
</tr>
<tr>
<td colspan="2"></td>
<td><strong>Total:</strong> {{totalEarning}} €</td>
<td></td>
</tr>
【问题讨论】:
-
您在 $scope.totalEarning 的日志中得到了什么?你能用一个简单的 jsfiddle/plunkr 重现这个吗?
-
对于 typeof $scope.totalEarning 我得到数字。对于 $scope.totalEarning,我只得到 NaN。
-
这是一个缩短的 plunkr 复制品:embed.plnkr.co/jb1iWOcjcm0alFchmzOH/preview
标签: angularjs firebase angularfire