ACE Agency
Angular

Build your first Angular appPart 4 of 6

Make the page react: signals and click events

At the end of part three your page showed one heading and did nothing else. This part gives it something to remember: a number that goes up when you click. It is the smallest possible piece of state, and it is enough to meet the four tools - signal, set, update and computed - that every Angular screen is built from.

By Adrien Colombier

7 min read

What you'll have at the end

  • A button that counts clicks, and a reset button
  • A value derived from another one with computed, that never goes stale
  • A message that only appears once the count is high enough, with @if
  • The three messages Angular gives you when you get one of these wrong

What you need

  • Part three finished: app.html reduced to your <h1>, ng serve running
  • About 10 minutes

Step 1

First, the warning you probably have

If you stopped the server after part three and started it again, it greeted you with this:

npm start, after part three
$ npm start ❯ Building...✔ Building...Initial chunk files | Names         | Raw sizemain.js             | main          |  2.60 kB | styles.css          | styles        | 95 bytes |                      | Initial total |  2.69 kB Application bundle generation complete. [1.251 seconds] - 2026-11-02T14:48:10.204Z ▲ [WARNING] NG8113: All imports are unused [plugin angular-compiler]     /home/you/my-first-angular-app/src/app/app.ts:5:2:      5 │   imports: [RouterOutlet],        ╵   ~~~~~~~  Watch mode enabled. Watching for file changes...NOTE: Raw file sizes do not reflect development server per-request transformations.  ➜  Local:   http://localhost:4200/

The app still builds - a warning is not an error - but it is worth understanding. The placeholder template you deleted ended with <router-outlet />, and RouterOutlet in imports is what made that tag work. The tag is gone, so the import is dead weight, and Angular says so.

Remove it for now. Part six brings it back, when the app has more than one page:

src/app/app.ts
  import { Component, signal } from '@angular/core';- import { RouterOutlet } from '@angular/router';   @Component({-   imports: [RouterOutlet],    selector: 'app-root',

Step 2

Store a number in a signal

You already have one signal: title. A signal is a box that holds a value and keeps a list of everyone who read it, so it can tell them when the value changes. That is how Angular knows which parts of the page to redraw - and nothing else.

Add a second one, starting at zero, and show it in the template:

src/app/app.ts
  export class App {    protected readonly title = signal('Angular');+   protected readonly count = signal(0);  }
src/app/app.html
  <h1>Built by me, with {{ title() }}</h1>++ <p>You clicked {{ count }} times.</p>

Look closely: there is a mistake in that template, and it is the most common one in Angular today. Save it and read the terminal:

❯ Changes detected. Rebuilding...✔ Changes detected. Rebuilding...Initial chunk files | Names | Raw sizemain.js             | main  |  2.87 kB |  Application bundle generation complete. [0.090 seconds] - 2026-11-02T14:48:25.334Z ▲ [WARNING] NG8109: NG8109: count is a function and should be invoked: count()}. Find more at https://v22.angular.dev/extended-diagnostics/NG8109 [plugin angular-compiler]     /home/you/my-first-angular-app/src/app/app.html:3:18:      3 │ <p>You clicked {{ count }} times.</p>        ╵                   ~~~~~   Warning occurs in the template of component App.     /home/you/my-first-angular-app/src/app/app.ts:6:15:      6 │   templateUrl: './app.html',        ╵                ~~~~~~~~~~~~  ▲ [WARNING] NG8117: NG8117: Function in text interpolation should be invoked: count(). Find more at https://v22.angular.dev/extended-diagnostics/NG8117 [plugin angular-compiler]     /home/you/my-first-angular-app/src/app/app.html:3:18:      3 │ <p>You clicked {{ count }} times.</p>        ╵                   ~~~~~   Warning occurs in the template of component App.     /home/you/my-first-angular-app/src/app/app.ts:6:15:      6 │   templateUrl: './app.html',        ╵                ~~~~~~~~~~~~  Page reload sent to client(s).

A signal is a function. {{ count }} puts the function itself on the page; {{ count() }} calls it and puts its value there. You saw the parentheses on title() in part three - they are not decoration. Add them, and the page reads You clicked 0 times.

Step 3

Change it on click

A writable signal has two ways to change: set gives it a new value outright, and update computes the new value from the old one. Add a method for each, and a computed signal while you are there:

src/app/app.ts
import { Component, computed, signal } from '@angular/core'; @Component({  selector: 'app-root',  styleUrl: './app.css',  templateUrl: './app.html',})export class App {  protected readonly title = signal('Angular');  protected readonly count = signal(0);  protected readonly doubled = computed(() => this.count() * 2);   protected increment() {    this.count.update((value) => value + 1);  }   protected reset() {    this.count.set(0);  }}

Then wire two buttons to those methods. In a template, an event name in parentheses - (click) - means "when this happens, run this":

src/app/app.html
<h1>Built by me, with {{ title() }}</h1> <p>You clicked {{ count() }} times. Doubled, that is {{ doubled() }}.</p> <button (click)="increment()">Click me</button><button (click)="reset()">Reset</button>
❯ Changes detected. Rebuilding...✔ Changes detected. Rebuilding...Initial chunk files | Names | Raw sizemain.js             | main  |  4.32 kB |  Application bundle generation complete. [0.124 seconds] - 2026-11-02T14:48:30.372Z Page reload sent to client(s).

Click. The number goes up, and doubled follows it without you ever writing a line that updates it. That is the point of computed: you describe how a value is derived, once, and Angular recalculates it only when count changes - and only if something on screen is reading it.

Handler names are checked when the app builds, not when someone clicks. Misspell one and you find out immediately:

❯ Changes detected. Rebuilding...✔ Changes detected. Rebuilding...Application bundle generation failed. [0.087 seconds] - 2026-11-02T14:48:36.338Z ✘ [ERROR] TS2551: Property 'incremnt' does not exist on type 'App'. Did you mean 'increment'? [plugin angular-compiler]     /home/you/my-first-angular-app/src/app/app.html:5:17:      5 │ <button (click)="incremnt()">Click me</button>        ╵                  ~~~~~~~~   Error occurs in the template of component App.     /home/you/my-first-angular-app/src/app/app.ts:6:15:      6 │   templateUrl: './app.html',        ╵                ~~~~~~~~~~~~

This one is an error, not a warning: nothing new reaches the browser until you fix it. The compiler even suggests the right name - templates are type-checked against your class like any other TypeScript. Fix the typo, save, and the next rebuild goes through.

Step 4

Show something only sometimes, with @if

Last piece. Add this at the bottom of app.html:

src/app/app.html
@if (count() >= 10) {  <p>Ten clicks. You can stop now.</p>}

The paragraph does not exist on the page until the condition is true - it is not hidden, it is absent. Click ten times and it appears; click Reset and it is removed again. @if also takes an @else block, which you will want the first time a list can be empty.

That is state in Angular: values in signals, changed by set and update, combined with computed, read in the template with parentheses. A shopping cart, a form or a search filter is the same thing with more signals in it.

Your App class is starting to fill up, though, and a real page would want more than one counter. Part five moves the counter into its own component, so you can put three of them on the page with one line each.

Next in this series

Part 5 of 6

Your first component: one counter, used three times

ng generate component, a label passed in with input(), three independent counters from one @for loop, and why track is not optional.

Your first component: one counter, used three times

We use Google Analytics to understand how the site is used and improve it. These cookies are only set with your consent. Learn more