2014-11-24 42 views
0

我有一個表格,其字段從ng-repeat。我已將兩個額外字段添加到每行,如輸入按鈕輸入和按鈕的角度表

我想要的是當我在輸入中輸入一些值並按下按鈕時,我想用相應輸入的值運行一個函數。我怎麼做?

我查看

<tr ng-click="" ng-repeat='customer in customers | filter:query | orderBy: sort.field : sort.order'> 

    <td ng-repeat='field in fields'> 
     {{customer[field]}} 
    </td> 
    <td> 
     <input class="form-control" name="debit" type="text"> 
    </td> 
    <td> 
     <button ng-click="genEcs(customer['id'])" class="btn btn-primary btn-sm" >ECS</button> 
    </td> 
</tr> 

我控制器

$scope.genEcs=function(id){ 

} 

回答

0

你需要通過ng-model屬性分配模型,以您的輸入。該模型將在ng-repeat每個customer的範圍定義,因爲ng-repeat創建子領域:

所以,你可以這樣做:

<tr ng-repeat='customer in customers> 
    <td> 
     <input class="form-control" ng-model="customersDebit" name="debit" type="text"> 
    </td> 
    <td> 
     <button ng-click="genEcs(customer, customersDebit)">ECS</button> 
    </td> 
</tr> 

(我還建議,爲便於閱讀和分離的緣故的問題,將整個customer對象傳遞給genEcs函數,而不僅僅是id字段。View對業務邏輯知道的越少越好)。