Creating Standalone Components
Declare components with the standalone flag.
Creating Standalone Components is a free Angular Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Angular Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
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.
Frequently asked questions
Is the “Creating Standalone Components” lesson free?
Yes — the full text of “Creating Standalone Components” is free to read here on the web, and the Angular Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Angular Academy course, upgrade to CoddyKit PRO.
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; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
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
- Why Standalone Components
- Creating Standalone Components
- Importing Dependencies Directly
- Bootstrapping a Standalone App