Counter (Standalone Component)

easy
By FrontendAtlas Editorial · Updated Oct 5, 2026
easy level
Standalone component setup Basic state management in a component Event binding and conditional disabling
Implement a standalone counter with increment, decrement, and reset. Guard the decrement at zero, disable the minus button when the value is 0, and keep state in a single component property for predictable behavior.
Standalone component setupBasic state management in a componentEvent binding and conditional disabling

Requirements

  • Use a standalone Angular component as the root component.
  • Display the current count value.
  • Provide "+", "-", and "Reset" buttons.
  • Disable the decrement button when the count is 0.

Expected behavior

  • Clicking "+" increases the count by 1.
  • Clicking "-" decreases the count by 1, but never below 0.
  • Clicking "Reset" sets the count back to 0.

Implementation notes

  • Use a regular class property (e.g. count = 0) to store state.
  • Use template event bindings like (click)="..." for button actions.
  • No need for child components, signals, or advanced patterns in this starter.

Solution idea

This exercise requires a single piece of state: the number of times the user has interacted with the counter. Store it in a component property (e.g. count = 0) on a standalone root component. Use three buttons wired with Angular event bindings to increment, decrement, and reset that state. Guard the decrement so the value never drops below zero and expose a simple derived flag to control the disabled state of the "-" button.