0
0
Angularframework~10 mins

Signals as modern state primitive in Angular - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Signals as modern state primitive
Create signal with initial value
Read signal value in template or code
Update signal value with set()
Signal notifies dependents
UI or computed values re-evaluate
User sees updated UI
Signals hold state and notify Angular when their value changes, triggering UI updates automatically.
Execution Sample
Angular
import { signal } from '@angular/core';

const count = signal(0);

count.set(1);
console.log(count());
This code creates a signal holding 0, updates it to 1, then logs the current value.
Execution Table
StepActionSignal Value BeforeSignal Value AfterEffect
1Create signal with initial value 0N/A0Signal initialized
2Read signal value with count()00Returns current value 0
3Update signal value with count.set(1)01Signal value updated, dependents notified
4Read signal value again with count()11Returns updated value 1
💡 No more actions; signal holds value 1 and UI would update accordingly
Variable Tracker
VariableStartAfter Step 1After Step 3Final
countundefined011
Key Moments - 3 Insights
Why do we call count() to read the signal value instead of accessing a property?
Signals are functions in Angular; calling count() returns the current value as shown in execution_table step 2 and 4.
What happens when we call count.set(1)? Does it immediately update the UI?
Calling set(1) updates the signal value and notifies dependents (step 3). Angular then schedules UI updates automatically.
Can we directly assign a new value to count like count = 2?
No, count is a signal function, not a variable. Use count.set(2) to update the value as shown in step 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the signal value after step 3?
A0
B1
Cundefined
D2
💡 Hint
Check the 'Signal Value After' column for step 3 in the execution_table.
At which step does the signal notify dependents about the value change?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for the 'Effect' column mentioning dependents notification in the execution_table.
If we replace count.set(1) with count.set(5), what changes in the variable_tracker?
AThe final value of count becomes 5
BThe start value changes to 5
CThe value after step 1 changes to 5
DNo change in variable_tracker
💡 Hint
Variable tracker shows signal value changes after set() calls; changing set value updates final.
Concept Snapshot
Signals are functions holding state in Angular.
Create with signal(initialValue).
Read value by calling signal(), e.g. count().
Update with signal.set(newValue).
Updates notify Angular to refresh UI automatically.
Full Transcript
Signals in Angular are a modern way to hold and manage state. You create a signal with an initial value using signal(). To read the current value, you call the signal as a function, like count(). To update the value, you use count.set(newValue). When the value changes, Angular automatically updates the UI where the signal is used. This makes state management simple and reactive without complex code.