javascript / beginner
Snippet
Derived State with computed()
The computed() function creates a read-only signal that automatically updates whenever its dependencies change. This is ideal for derived data.
snippet.js
1
2
count = signal(10);doubleCount = computed(() => this.count() * 2);
angular
Breakdown
1
computed(() => ...)
Defines a derivation logic that runs only when the underlying signals change.
2
this.count()
Calls the signal as a function to track it as a dependency.