9

如何创建具有 + 和 - 按钮的输入框。单击哪个用户可以更改所选产品的数量,例如此屏幕:

具有 + 和 - 按钮的输入框

4

2 回答 2

5

这是 Ionic 2 的快速组合示例。如果您使用的是 Ionic 1,您应该能够很容易地适应它。

您只需要几个控制器/类函数来递增和递减,然后通过按钮调用这些函数。这个例子只包含一个按钮,所以像这样的东西包裹在一个ngFor或一个<ion-list>

page.ts:

private currentNumber = 0;
constructor () { }

private increment () {
  this.currentNumber++;
}

private decrement () {
  this.currentNumber--;
}

page.html:

<ion-icon name="remove-circle" (click)="decrement()">
{{currentNumber}}
<ion-icon name="add-circle" (click)="increment()">
于 2016-08-09T22:58:14.973 回答
5

至于您模板中的 ionic v.1,您可能会有类似的内容:

<div class="flex_row">
  <button class="button icon ion-minus-circled red" ng-click="sub(item)">
  <p> {{item.quantity}} </p>
  <button class="button icon ion-plus-circled green" ng-click="add(item)">
</div>

在你的 CSS

    .red:before {
    color: red;
    }

    .green:before {
    color: green;
    }

    .flex_row {
    display: -webkit-flex;
    display: flex;
    -webkit-flex-direction: row; 
    flex-direction: row;
    }

在你的控制器中

$scope.sub = function(i) {
  i.quantity--;
}

$scope.add = function(i) {
  i.quantity++;
}
于 2016-08-10T14:23:11.213 回答