Skip to the workspace
Pebellslearn by building
Components  ›  Lesson

Standalone Components and Imports

Standalone 12 minModern Angular components are standalone, so each one lists in its imports array exactly the components, directives and pipes its template uses.

angular / Standalone Components and Imports

Explore each scene at your own pace.

01 · The rule

The rule

Standalone Components and Imports

You drop <app-plant-card> into PlantList's template and Angular answers: "'app-plant-card' is not a known element." The card exists and works elsewhere. The fix is one line, and understanding it explains how modern Angular is organised.

The rule

A standalone component imports everything its template uses.

A standalone component manages its own dependencies. It is the default: in current Angular every component, directive and pipe is standalone unless you write standalone: false. (Between versions 14 and 18 you had to write standalone: true yourself, so you will see it in older code.)

Its imports array lists the components, directives and pipes its template needs:

import { Component, input } from '@angular/core';
import { DatePipe } from '@angular/common';
import { RouterLink } from '@angular/router';
import { PlantCard } from './plant-card';

@Component({
  selector: 'app-plant-list',
  imports: [PlantCard, DatePipe, RouterLink],
  template: `
    <a routerLink="/plants/new">Add plant</a>
    @for (p of plants(); track p.id) {
      <app-plant-card [plant]="p" />
      <small>Last watered {{ p.lastWatered | date }}</small>
    }
  `,
})
export class PlantList {
  plants = input.required<Plant[]>();
}

What does not go in imports:

  • Built-in blocks such as @if, @for, @switch. They are part of the template language.
  • Services. Those arrive through dependency injection, not through the template.
  • Things used only in the class code, like a helper function. A normal TypeScript import line is enough.

Before standalone, components were declared inside an NgModule, and got their dependencies from whatever that module imported. You still meet this in older apps; the standalone style makes each file tell its own story.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.