2016-12-02 52 views
0

通過使用angularjs IM乘以兩個值,但是當我上添加按鈕,點擊它應顯示婁文本框狀如何在div下插入記錄?

price 10 qty 2 total 20 --->Add> 

Price qty Total 
10  2  20 

HTML代碼

<div class="row"> 
    <div ng-controller="Supercntrl"> 
     <div class="form-inline" id="Mom"> 
      Price <input type="text" ng-model="price" class="form-control" /> 
      quentity <input type="text" ng-model="Quantity" class="form-control" ng-change="Claci()" /> 
      Total <input type="text" ng-model="Total" class="form-control" /> 

      <input type="button" class="btn btn-sm btn-success" value="Add" ng-click="AddDetails()" /> 

     </div> 
     <div > 
//Display Insered Record 
      </div> 
    </div> 
</div> 

Controller.Js

$scope.Claci = function() { 
      if ($scope.price != null && $scope.Quantity != null) { 
       $scope.Total = $scope.price * $scope.Quantity 
      } 
     } 

請提出e我如何顯示打好值怒吼出它的

回答

1

HTML:

<div> 
    <!-- //Display Insered Record --> 
    <ul ng-repeat="total in totals"> 
     <li>Price: {{total.price}}</li> 
     <li>Quantity: {{total.quantity}}</li> 
     <li>Total: {{total.total}}</li> 
    </ul> 
</div> 

添加到控制器:

$scope.totals = [] 
$scope.AddDetails = function() { 
    $scope.totals.push({ 
     price: $scope.price, 
     quantity: $scope.Quantity, 
     total: $scope.Total 
    }) 
    console.log($scope.totals) 
} 

的jsfiddle演示https://jsfiddle.net/eqL7mj9r/