1e41f4b71Sopenharmony_ci# Counter
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **Counter** component provides an operation to increase or decrease the number.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciSupported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## APIs
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ciCounter()
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci## Attributes
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciIn addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci### enableInc<sup>10+</sup>
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_cienableInc(value: boolean)
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciSets whether to enable the increment button.
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Parameters**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                 |
40e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------- |
41e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether to enable the increment button.<br>Default value: **true**|
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci### enableDec<sup>10+</sup>
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_cienableDec(value: boolean)
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ciSets whether to enable the decrement button.
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci**Parameters**
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci| Name| Type   | Mandatory| Description                                 |
56e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ------------------------------------- |
57e41f4b71Sopenharmony_ci| value  | boolean | Yes  | Whether to enable the decrement button.<br>Default value: **true**|
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci## Events
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ciIn addition to the [universal events](ts-universal-events-click.md), the following events are supported.
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci### onInc
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_cionInc(event: () =&gt; void)
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciInvoked when the value increases.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci### onDec
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_cionDec(event: () =&gt; void)
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ciInvoked when the value decreases.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**Widget capability**: This API can be used in ArkTS widgets since API version 9.
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 11.
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci**System capability**: SystemCapability.ArkUI.ArkUI.Full
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci## Example
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci```ts
91e41f4b71Sopenharmony_ci// xxx.ets
92e41f4b71Sopenharmony_ci@Entry
93e41f4b71Sopenharmony_ci@Component
94e41f4b71Sopenharmony_cistruct CounterExample {
95e41f4b71Sopenharmony_ci  @State value: number = 0
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci  build() {
98e41f4b71Sopenharmony_ci    Column() {
99e41f4b71Sopenharmony_ci      Counter() {
100e41f4b71Sopenharmony_ci        Text(this.value.toString())
101e41f4b71Sopenharmony_ci      }.margin(100)
102e41f4b71Sopenharmony_ci      .onInc(() => {
103e41f4b71Sopenharmony_ci        this.value++
104e41f4b71Sopenharmony_ci      })
105e41f4b71Sopenharmony_ci      .onDec(() => {
106e41f4b71Sopenharmony_ci        this.value--
107e41f4b71Sopenharmony_ci      })
108e41f4b71Sopenharmony_ci    }.width("100%")
109e41f4b71Sopenharmony_ci  }
110e41f4b71Sopenharmony_ci}
111e41f4b71Sopenharmony_ci```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci![en-us_image_0000001212378424](figures/en-us_image_0000001212378424.gif)
114