Creating and Reading Signals
Declare writable signals and read their values.
Creating a Signal
You create a writable signal with the signal() factory, passing the initial value.
import { signal } from '@angular/core';
const c = signal(0); // initial value is 0The Initial Value Sets the Type
TypeScript infers the signal type from the initial value. signal(0) is a WritableSignal<number>.
const name = signal('Alice'); // WritableSignal<string>
const flag = signal(false); // WritableSignal<boolean>All lessons in this course
- What Are Signals
- Creating and Reading Signals
- Updating Signals with set and update
- Signals in Templates