1 of 19

Angular Signals

What you need to know

Tran Nguyen - 04/11/2023

1

v16

2 of 19

Agenda

  • What is Signals?
  • How it works?
  • Signals and change detection OnPush.
  • Will Signals replace RxJS?

2

3 of 19

What is Signals?

3

4 of 19

Why not continue with zone.js?

  • Review Change Detection in Angular

4

OnDefault

OnPush

5 of 19

Have you ever wondered…

5

6 of 19

Are we going to have another change detection strategy?

6

7 of 19

❤️

7

Signals

That’s the problem Signals solve for us

8 of 19

What is Signals

8

Signals

+

9 of 19

What is Signals

A variable + change notification

9

Observed

Update

Notify

dependents

Always

has a value

Synchronous

10 of 19

Example

10

  • What are dependents in Signals
  • How to notify them

11 of 19

How it works

11

signal<T>(initialValue: T): WritableSignal<T>

  • Writable Signal

12 of 19

  • set(): set the signal to a new value.
  • update(): store a new value created from the current value.
  • mutate(): directly modifies the current value.
  • asReadonly(): returns a new signal that stores the same value but does not allow it to be modified.

12

13 of 19

Signals and Change detection OnPush

  • Demo

13

14 of 19

  • Demo

14

15 of 19

Does Signal give us any benefit over OnPush Strategy?

15

Should we remove zone.JS?

16 of 19

16

🤜🤛

Signals

Behaviour Subject

17 of 19

17

  • Has initial value

18 of 19

18

👉 Observable

19 of 19

DEMO

This demo will answer those questions:

  • Issue with RxJS
  • Will signals replace RxJS
  • Is there any issue with signals
  • How signals and RxJS works together

19