如何在Ionic中创建一个带+和 - 按钮的输入框 [英] How create an input box having a + and - button in Ionic

查看:124
本文介绍了如何在Ionic中创建一个带+和 - 按钮的输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How I can create an input box having a + and - button. Clicking upon which user can change the quantity of product selected, like this screen:

推荐答案

这是Ionic 2的一个快速抛出的例子。如果你正在使用Ionic 1,你应该可以很容易地适应它。

Here's a quickly thrown together example for Ionic 2. If you are using Ionic 1 you should be able to adapt it pretty easily.

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

You just need a couple controller/class functions to increment and decrement, then call those on tap from the buttons. This example covers just one button, so something like this wrapped in an ngFor or a <ion-list>

page.ts:

private currentNumber = 0;
constructor () { }

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

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

page.html:

page.html:

<ion-icon name="remove-circle" (click)="decrement()">
{{currentNumber}}
<ion-icon name="add-circle" (click)="increment()">

这篇关于如何在Ionic中创建一个带+和 - 按钮的输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆