1
所以我有兩天的角度問題,有沒有一種方法來總結所有的角度數據沒有控制器?角度沒有控制器的所有值的總和
我想從所有小計打印totalPrice,我試圖用方法getTotalPrice()中的控制器來總結,但我不知道如何打發小計陣列
@foreach($products as $product)
<div class="form-group" ng-init="qty_{{$product->id}}=0">
{{Form::label($product->id, $product->name.' - '.$product->price, array('class'=>'col-md-4 control-label'))}}
<input type="hidden" ng-model="price_{{$product->id}}" ng-init="price_{{$product->id}}={{$product->price}}">
<div class="col-md-2">
<input id="{{$product->id}}" type="number" min="0" value="0" step="1" class="form-control" name="qty_{{$product->id}}" ng-model='qty_{{$product->id}}'>
</div>
<div class="col-md-6">
<label for="" class="col-md-10 control-label"><% qty_{{$product->id}} * {{$product->price}} %></label>
</div>
</div>
<br>
@endforeach
<div class="form-group">
<div class="col-md-6 col-md-offset-6">
<label for="" class="col-md-6 control-label">Total Price</label>
<label for="" class="col-md-4 control-label" ng-model="totalPrice" ng-init="totalPrice = 0" ng-value="<% getTotalPrice() %>"><% getTotalPrice() %></label>
</div>
</div>
我的繼承人電流控制器
myApp.controller('cashierController', ['$scope', function($scope){
$scope.subTotal = [];
$scope.getTotalPrice = function(subTotal) {
var totalPrice = 0;
for(sub in subTotal){
totalPrice += sub;
}
return totalPrice;
}
}]);
PS:我在laravel中使用角度 對不起,如果有任何奇怪的代碼,請提前致謝。
發佈HTML,而不是PHP代碼。 – dfsq
你應該添加一些按鈕或其他東西,並添加ng-click =「getTotalPrice(totalPrice)」 – Erez