Angular: NG8103: The *ngIf directive was used, but neither the NgIf directive nor the CommonModule was imported
A standalone component uses *ngIf, *ngFor or ngClass without importing the directive — or should migrate to the built-in @if / @for control flow.
The *ngIf directive was used in the template, but neither the NgIf directive nor the CommonModule was importedThe *ngFor directive was used in the template, but neither the NgFor directive nor the CommonModule was importedneither the NgIf directive nor the CommonModule Meaning
Standalone components do not get CommonModule for free. Either import the directive you use (NgIf, NgFor, NgClass) or move to the new block syntax (@if, @for, @switch), which needs no import at all.
Common causes
- Standalone component using
*ngIf/*ngFor/ngClass/ngStylewithout importing them - Component generated as standalone but old templates pasted from an NgModule project
CommonModuleremoved from an NgModule that declares the component- Using
NgForsyntax insideng-templateof another component without its import
⚡ Quick fix
- Replace with
@if/@for(no imports) - Or add
NgIf,NgFor,NgClassto the component'simports - Run the control-flow migration schematic
Detailed fix by platform
Angular CLI
- Migrate automatically:
ng generate @angular/core:control-flow - Manual:
imports: [NgIf, NgFor]from@angular/common
Code examples
Built-in control flow
<!-- before: <li *ngFor="let u of users">{{ u.name }}</li> -->
@if (users.length) {
<ul>
@for (u of users; track u.id) {
<li>{{ u.name }}</li>
}
</ul>
} @else {
<p>No users yet</p>
}How to diagnose
- Component — Standalone or in an NgModule?
- Directive — Which structural directive is used?
- Version — Angular 17+ (control flow available)?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- NG02200 Angular: NG02200: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays
- NG0301 Angular: NG0301: Export of name 'x' not found! (template variable #x="exportAs")
- NG0955 Angular: NG0955: The provided track expression resulted in duplicated keys for a given collection (@for)
Most viewed in Angular
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026