2016-07-29 35 views
0

我试图将两个字段放在一起并拿出总和。但isssue是当我将ng模型添加到其中一个文本域时,其中的绑定值消失。当我从中删除ng模型时,绑定值显示出来。如何在使用ng-model时使绑定值出现在文本字段中。使用两个字段进行计算,其中一个使用角度为ng的模型

<div ng-controller="items" ng-repeat="item in data"> 
    <label class="item item-input"> 
     <span class="input-label">Current Quantity</span> 
     <input type="text" value="{{item.quantity}}" ng-model="first"> 

     </label> 
     <label class="item item-input"> 
     <span class="input-label">New Stock</span> 
     <input type="text" placeholder="New stock about to be added" ng-model="second"> 
     </label> 
     <br> 
    <h1> New Stock: {{first--second}}! </h1> 
</div> 

JS

.controller('updatestock_ctrl',['$scope','$http','$state','$stateParams',function($scope,$http,$state,$stateParams){ 
    $http.get('http://localhost/masa/templates/spree/stocks/update_stock.php?item_id='+$stateParams.item_id).success(function(data){ 
     console.log(JSON.stringify(data)); 
     $scope.data=data; 
     }); 
}]) 
+3

第一,尽量不要使用值,但只是ng-model:'' – rgthree

+0

感谢它的工作。 – user6579134

+0

@rgthree应该添加一个答案,以便可以显示此问题已解决。 – Lex

回答

0

除了使用value HTMLAttribute为输入的,你应该只声明ng-model,它会自动扳平值读取和写入:

<input type="text" ng-model="item.quantity"> 
相关问题