我是新來的angularjs。如何獲得表總金額列中的總金額並在輸入文本框中顯示?我認爲這名運動員可以解決我的問題,但我現在無法訪問它。 http://plnkr.co/edit/CHBm8RCqW5RNZWrzAe5r?p=preview如何獲得angularjs中列的總值?
這裏是我的表樣
<table>
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="payment_queue in data | filter:searchFilter">
<td>{{payment_queue.product_name}}</td>
<td>{{payment_queue.sold_quantity}}</td>
<td>{{payment_queue.amount}}</td>
</tr>
</tbody>
</table>
Total Amount: <input type="text value=""> <--- the total amount value goes here...
JS
var myApp = angular.module('myApp', ['ngRoute']);
myApp.controller('productsalesController', ['$scope', '$http', function ($scope, $http) {
$scope.data=[];
$http.get("../php/paymentQueuedata.php")
.success(function(data){
$scope.data = data;
})
.error(function() {
$scope.data = "error in fetching data";
});
}]);
PHP JSON
<?php
//database settings
$connect = mysqli_connect("localhost", "root", "", "rmsdb");
$result = mysqli_query($connect, "select * from payment_queue");
$data = array();
while ($row = mysqli_fetch_array($result)) {
$data[] = $row;
}
print json_encode($data);
?>
您需要在您的控制器中計算它並將其分配給'$ scope'變量。然後你可以使用'>'。角度並不便宜。 – mostruash
[計算AngularJS ng-repeat中重複元素的總和]的可能副本(http://stackoverflow.com/questions/22731145/calculating-sum-of-repeated-elements-in-angularjs-ng-repeat) – marapet
請分享你的樣品json –