Angular Academy · Lesson

Creating Standalone Components

Declare components with the standalone flag.

Lesson 2 of 413 steps

Creating Standalone Components is a free Angular Academy lesson on CoddyKit. This is lesson 2 of 4. Any 3 lessons of this learning path are free to read in full — after that, CoddyKit PRO unlocks every lesson, plus hands-on practice with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, and your progress syncs across the web and the CoddyKit app. The Angular Academy course includes 4 lessons in total.

Creating a Standalone Component

A standalone component is just a class decorated with @Component that is marked standalone. In Angular v19+ this is the default, so you often do not even write the flag.

The standalone Flag

Historically you set standalone: true in the decorator. In v19 and later, components are standalone by default, so the flag is optional.

import { Component } from '@angular/core';

@Component({
  selector: 'app-greeting',
  standalone: true, // optional in v19+
  template: '<h1>Welcome</h1>'
})
export class GreetingComponent {}

Selector

The selector is the custom element tag used to place the component in a template, such as app-greeting.

// usage in another template:
// <app-greeting></app-greeting>

Inline Template

Use the template property for inline HTML, ideal for small components.

@Component({
  selector: 'app-badge',
  template: '<span class="badge">New</span>'
})
export class BadgeComponent {}

External Template

For larger views, use templateUrl to point to an HTML file.

@Component({
  selector: 'app-profile',
  templateUrl: './profile.component.html'
})
export class ProfileComponent {}

Styles

Add component-scoped styles with styles (inline) or styleUrl / styleUrls (external files).

@Component({
  selector: 'app-card',
  template: '<div class="card"></div>',
  styles: ['.card { padding: 16px; }']
})
export class CardComponent {}

Component Class Logic

The class body holds state and behavior. With signals, declare reactive state as fields.

import { Component, signal } from '@angular/core';

@Component({ selector: 'app-counter', template: '<p>{{ n() }}</p>' })
export class CounterComponent {
  n = signal(0);
}

No Module Needed

Notice there is no @NgModule and no declarations array. The component is ready to be imported wherever it is needed.

File Naming Convention

Angular convention names files like greeting.component.ts, the class GreetingComponent, and the selector app-greeting.

Using One Component Inside Another

To use a child standalone component, import it in the parent component imports array (covered next lesson) and place its selector in the parent template.

Generating with the CLI

The Angular CLI generates standalone components by default. Running ng generate component greeting scaffolds a standalone GreetingComponent for you.

Quick Check: Creating Components

About standalone defaults.

Recap: Creating Standalone

You create a standalone component with @Component, optionally setting standalone: true (the default in v19+). You define a selector, template or templateUrl, optional styles, and class logic. No NgModule is required. Next: importing dependencies directly.

Free to start

Learn HTML with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
38
Lessons
144

Frequently Asked Questions

Is the “Creating Standalone Components” lesson free?

Yes — any 3 lessons of the Angular Academy learning path, including “Creating Standalone Components”, are free to read in full here on the web. After that, CoddyKit PRO unlocks every lesson, plus interactive practice with a built-in code editor and a 24/7 AI tutor. The Angular Academy course includes 4 lessons in total.

What will I learn in “Creating Standalone Components”?

Declare components with the standalone flag. You practise Angular Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Angular Academy?

No prior experience is required. Angular Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Creating Standalone Components” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Angular Academy lesson?

Yes. Every Angular Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Why Standalone Components
  2. Creating Standalone Components
  3. Importing Dependencies Directly
  4. Bootstrapping a Standalone App
← Back to Angular Academy