Counter (Standalone Component)

easy
By FrontendAtlas Editorial · Updated Nov 12, 2026
easy level
Standalone component setupSignal state with signal, update and computedEvent 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 the count in one signal so every binding that shows it updates with it.

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.

What the checks look for

The checks find elements by .value, button "-", button "+", button "Reset". Keep these in your markup.

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

  • Hold the count in a signal (count = signal(0)) and change it with update or set; the template reads it as count(). A plain count = 0 field also works here, because every change comes from a click in this template.
  • Use template event bindings like (click)="..." for button actions.
  • Derive the disabled state with computed instead of repeating count() === 0 in the template. No child components are needed.

Solution idea

The counter needs one piece of state, the current count. The solution keeps it in a signal, count = signal(0), on the standalone root component and derives isZero from it with computed. The three buttons call inc(), dec() and reset(), which change the signal with update and set. The template reads count() and binds [disabled]="isZero()" on the minus button, so Angular knows which bindings depend on the count and the component can use OnPush change detection.