NG.II · Angular 22 practice question
A developer implements a service that uses `effect()` to log changes to a global configuration signal. This service is provided at the root level of the application. When the application starts and change detection begins, when will this logging effect execute relative to the rendering of any component?
import { Injectable, signal, effect } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class ConfigService {
config = signal({ theme: 'dark' });
constructor() {
effect(() => {
console.log('Config changed:', this.config());
});
}
}
Check answer and explanation
Correct answer: It will execute before any component is checked during the change detection process.
Explanation
An effect established within a service provided at the root level is categorized as a Root Effect, meaning it runs before the change detection process examines any component.
Common trap
The description stating that the effect runs immediately following the completion of Angular's change detection cycle for all components actually describes the behavior of a View Effect, which executes before its associated component is checked.
Source: Angular docs: Effects — Execution of effects
Checked against the cited text on 2026-11-25.