2016-10-05 80 views

回答

0
ReceiptsApp.controller('ReceiptsController', function ($scope) { 
$scope.rvm = [{}]; 
    $scope.addRow1 = function (index, r) { 
     // pass the particular array object on which you want to perform calculations when the function is called from ng-click and access those particular objects values using r.val1 and r.val2 
     //Access particular "rvm" object using index 
     $scope.rvm[index].result = r.val1 - r.val2; 
     if ($scope.rvm.length == (index + 1)) { 
      $scope.rvm.push({ 
      }); 
     } 

    } 

var ReceiptsApp = angular.module('ReceiptsApp', []); 

ReceiptsApp.controller('ReceiptsController', function ($scope) { 
$scope.rvm = [{}]; 
    $scope.addRow1 = function (index) { 
     //alert('ss'); 
     $scope.result = $scope.r.val1 - $scope.r.val2; 
     if ($scope.rvm.length == (index + 1)) { 
      $scope.rvm.push({ 
      }); 
     } 

    } 


}); 

查找代碼在HTML

<td> 
    <input type="text" lass="input-large" ng-model="r.result" name="res" /> 
    </td> 
<td> 
    <button type="button" class="btn btn-default" ng-click="addRow1($index, r)">Add</button> 
</td> 

工作JSBin

+0

是否回答你的問題或你是否面臨任何問題? –

+0

謝謝拉維,在我的要求,我有添加按鈕出NG重複和代碼在這裏https://jsbin.com/repanijitu/edit?html,js,output的側 –

+0

你是說你只想有'one'添加按鈕? –