← Back to Angular, page 8

angular-0160 · Easy fresher

Angular shows "is not a known element" or "Can't bind to X since it isn't a known property of Y". What causes these errors and how do you fix them?

In a standalone component, every component, directive or pipe used in the template must be listed in that component's imports array. These errors mean the compiler found a tag or binding that no imported item defines. Fix by importing the right standalone class (or FormsModule, RouterLink and so on), or by correcting a typo.

Full answer

These are the most common errors for beginners. They are template errors that the compiler reports (NG8001 for an unknown element, NG8002 for an unknown property), and in a test or JIT run you may see them in the console.

Typical messages:

  • NG8001: 'app-student-card' is not a known element. Angular found a tag that is not a standard HTML tag and not a component it knows.
  • NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'. Angular found a binding such as [ngModel] or [routerLink] and no imported directive provides that input.
  • NG8004: No pipe found with name 'currency'. A pipe is used but not imported.

Why it happens: in standalone components (the default now) the template can only use what the component lists in imports. Nothing is global, unlike old NgModules where one module declared many things.

Fix by checking, in order:

  1. Is the item imported? Add the class: imports: [StudentCardComponent], imports: [FormsModule] for ngModel, imports: [RouterLink], imports: [ReactiveFormsModule] for formGroup, and CurrencyPipe for the currency pipe. The built-in control flow (@if, @for) needs no import, but NgClass and NgStyle must be imported like any other directive.
  2. Is the selector spelt correctly? app-student-card in the template must match the selector in the component. A typo gives the same error.
  3. Is the imported class standalone? A component that is declared in an NgModule must be imported through that module.
  4. Is the input real? [disable] instead of [disabled] is "not a known property". Check the name in the component's input().
  5. Did you forget the [] or use a custom element? For Web Components, add CUSTOM_ELEMENTS_SCHEMA to schemas, but do not use it to silence real mistakes, because it hides typos.

In tests: declare or import the component under test, and its dependencies, in TestBed.

Learn the habit: when the editor shows the error, read the name in quotes, and ask "which class provides this, and is it in my imports?"

typescript
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { CurrencyPipe } from '@angular/common';

@Component({
  selector: 'app-fee-card',
  template: `<p>Fee card</p>`,
})
export class FeeCardComponent {}

// Broken: nothing is imported. ngc reports:
//   NG8001: 'app-fee-card' is not a known element
//   NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
//   NG8004: No pipe found with name 'currency'
//   @Component({
//     selector: 'app-fee-form',
//     template: `<app-fee-card /> <input [(ngModel)]="fee" /> {{ fee | currency }}`,
//   })
//
// Fixed: import each item that the template uses.
@Component({
  selector: 'app-fee-form',
  imports: [FeeCardComponent, FormsModule, CurrencyPipe],
  template: `<app-fee-card /> <input [(ngModel)]="fee" name="fee" /> {{ fee | currency }}`,
})
export class FeeFormComponent {
  fee = 1500;
}

Angular 20.3. The compiler messages in the code comment were produced by running `ngc` on the broken version of this component, and the fixed version compiles cleanly.

Key points

  • In standalone components, only items listed in `imports` can be used in the template.
  • NG8001 is an unknown element, NG8002 is an unknown property, NG8004 is an unknown pipe.
  • Fix by importing the class, correcting a typo, or importing the right module.
  • Use `CUSTOM_ELEMENTS_SCHEMA` only for real Web Components.

Common mistakes

  • Silencing errors with `CUSTOM_ELEMENTS_SCHEMA` or `NO_ERRORS_SCHEMA`.
  • Importing a module into the parent and expecting the child to see it.
  • Spelling the selector or input name wrongly.

Follow-ups

  • Why does a child component not inherit the parent's imports?
  • What does `NO_ERRORS_SCHEMA` hide?
  • How do you fix this error in a unit test?

Tips

  • Give the checklist in order.
  • Say that imports are per component.
  • Warn against schemas as a shortcut.

Evaluation rubric

  • Explains the cause in standalone terms.
  • Gives a clear fix order.
  • Avoids bad shortcuts.