Full answer
These come up in code reviews again and again.
-
ExpressionChangedAfterItHasBeenChecked (NG0100). In development mode Angular checks twice. If a value used in a template changes between the two passes, it throws. Typical cause: a child changes parent state in
ngAfterViewInitorngOnInit, after the parent was already rendered. Fix: change the data flow (the parent owns the state and passes it down, or the child emits an event), compute values withcomputed, or move the change into a later task. Not a fix: hiding the error withsetTimeoutwithout understanding the cause, ordetectChanges()calls. -
Heavy function calls in templates.
{{ getTotal() }}runs on every change detection pass. Use acomputedsignal or a pure pipe. -
Nested subscribes. A
subscribeinside asubscribecreates callback pyramids, leaks, and race conditions. UseswitchMap,concatMap, orforkJoin. -
Mutation. Pushing into an array or editing an object that an OnPush child received. The view does not update. Create a new array or object, or use signal
updatewith spread syntax. -
Missing cleanup. Subscribing to
interval,valueChanges, or router events withouttakeUntilDestroyed, theasyncpipe, ortoSignal. -
Missing or poor
trackin@for(ortrackByin the legacy*ngFor), causing DOM rebuilds. -
Putting logic in components that belongs in services, making testing hard.
-
Using
any. It removes the checks that the typed forms, typed HTTP, and strict templates provide. Turn onstrictandstrictTemplates. -
Importing a whole module or a large library for one function, which inflates the bundle.
-
Not handling HTTP errors. A one-shot HTTP call needs no unsubscribe, but a failed call still needs a visible message or a fallback.
The example below shows the fixed forms of items 2, 3, 4, and 5 in one component.
import { HttpClient } from '@angular/common/http';
import { Component, computed, inject, input, signal } from '@angular/core';
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
import { catchError, of, switchMap } from 'rxjs';
interface Student {
id: number;
name: string;
marks: number;
}
interface Detail {
id: number;
address: string;
}
@Component({
selector: 'app-student-table',
template: `
<p>Average: {{ average() }}</p>
<button (click)="addStudent()">Add</button>
@for (s of sorted(); track s.id) {
<button (click)="selectedId.set(s.id)">{{ s.name }} ({{ s.marks }})</button>
}
<p>{{ detail()?.address ?? 'Select a student' }}</p>
`,
})
export class StudentTableComponent {
private readonly http = inject(HttpClient);
readonly students = input.required<Student[]>();
readonly extra = signal<Student[]>([]);
readonly selectedId = signal<number | null>(null);
// Item 2. Old form: {{ getAverage() }} called on every change detection pass.
readonly all = computed(() => [...this.students(), ...this.extra()]);
readonly average = computed(() => {
const list = this.all();
return list.length ? Math.round(list.reduce((sum, s) => sum + s.marks, 0) / list.length) : 0;
});
readonly sorted = computed(() => [...this.all()].sort((a, b) => b.marks - a.marks));
// Items 3 and 5. Old form: subscribe inside subscribe with no cleanup.
readonly detail = toSignal(
toObservable(this.selectedId).pipe(
switchMap((id) =>
id === null
? of<Detail | null>(null)
: this.http.get<Detail>(`/api/students/${id}`).pipe(catchError(() => of<Detail | null>(null))),
),
),
{ initialValue: null },
);
// Item 4. Old form: this.extra().push(...) which signals cannot detect.
addStudent(): void {
this.extra.update((list) => [...list, { id: 100 + list.length, name: 'New', marks: 50 }]);
}
}Angular 20.3, strict template check passes. The comments mark the old form of each pattern, which should not be written in new code.
Key points
- NG0100 means state changed after it was rendered. Fix the data flow, not the symptom.
- Replace template function calls with `computed` or a pure pipe.
- Replace nested subscribes with flattening operators, and clean up with `toSignal` or `takeUntilDestroyed`.
- Use immutable updates with OnPush and give `@for` a stable `track`.
Common mistakes
- Fixing NG0100 with `setTimeout` and leaving the real design problem in place.
- Turning off strict mode when the compiler complains instead of fixing the types.
- Using `ChangeDetectorRef.detectChanges()` as a general repair tool.
Follow-ups
- How would you reproduce NG0100 on purpose?
- Why is a template function call different from a `computed`?
- Which of these would you flag first in a code review, and why?
Tips
- Prefer a real story from a review or debugging session in your own words, with the cause and the fix.
- Always explain why a pitfall happens, not only the fix.
- Say that you enable strict compiler options so many of these are caught early.
Evaluation rubric
- Explains NG0100 and its real fixes.
- Gives correct replacements for common anti-patterns.
- Shows awareness of strict settings and review habits.