在同一行离子点击相应按钮的同时增加文本框的值

时间:2016-10-06 06:57:07

标签: angularjs ionic-framework

我是离子和棱角分明的新手。我已经创建了一个带有ng-repeat的表单,如图所示。我有一个文本框和每个文本框的按钮。我想在文本框旁边点击相应按钮的同时增加文本框的值。

<ion-list id="allitems" ng-repeat="item in items track by $index">
<ion-item>
<form id="form1">
<div class="row">
<input type="text" id="nos_{{ $index }}"  name="nos_{{ $index }}" ng-model="data.myitem.nos" > 
<button class="button button-assertive button-small button-outline icon ion-ios-minus" id="allitems-button10" ng-click="increment_nos($index)">        
</button>
</div>
</form>
</ion-item>
</ion-list>

我的控制器功能如下

.controller('allitemsctrl', ['$scope', '$stateParams', '$location', '$timeout','$window', 
function ($scope, $stateParams, $location, $timeout,$window) {   
$scope.items = [{'id': '1', 'item_name': 'abc'}, {'id': '2', 'item_name': 'xyz'}, {'id': '3','item_name': 'pqr'}];
var data = {};
$scope.data = {};             
$scope.increment_nos = function (index) {
//I want to increase value of nos while click on corresponding button near nos textbox                    
}             
}])

1 个答案:

答案 0 :(得分:0)

您应首先将单独的值链接到每个文本框

ng-model="items[$index].nos"

然后,在控制器中增加该值:

$scope.increment_nos = function (index) {
    items[index].nos = items[index].nos + 1;
}

但首先将初始值设置为nos为0