Angular: NG8113: NgIf is not used within the template of AppComponent — unused standalone import
A standalone component lists a directive, pipe or component in imports but never uses it in its template.
is not used within the template ofunused standalone importsNgIf is not used within the templateNgFor is not used within the template Meaning
The compiler warns (Angular 19+) so bundles do not carry dead code. After moving to @if / @for, the old NgIf / NgFor imports become unused. Remove the import, or if you really need it only in TypeScript, do not list it in imports.
Common causes
- Migrated to
@if/@forand leftNgIf/NgForinimports - Component or pipe removed from the template but still imported
- Copy-pasted
importsarray from another component - Directive used only in a different component's template
⚡ Quick fix
- Delete the unused item from the
importsarray - Run the cleanup schematic
- Keep the warning as an error in CI to prevent drift
Detailed fix by platform
Angular CLI
ng generate @angular/core:cleanup-unused-importsremoves them automatically (Angular 19+)
Code examples
Trim imports
@Component({
selector: 'app-list',
standalone: true,
// imports: [NgIf, NgFor, JsonPipe], // NG8113 for each one the template no longer uses
imports: [JsonPipe],
template: `@for (i of items; track i.id) { <pre>{{ i | json }}</pre> }`,
})
export class ListComponent { items = [{ id: 1 }]; }How to diagnose
- Template — Is the item referenced anywhere in the template?
- Migration — Did you move to @if / @for?
- Version — Angular 19+?
🔧 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")
- NG6008 Angular: NG6008: Component X is standalone, and cannot be declared in an NgModule. Did you mean to import it instead?
Most viewed in Angular
- NullInjectorError Angular: NullInjectorError: No provider for X!
- NG0100 Angular: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked
- NullInjectorError: No provider for HttpClient! Angular: NullInjectorError: No provider for HttpClient! — provideHttpClient() missing
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