In Angular 15+, standalone components let you build features without using NgModules. This simplifies your app structure, reduces boilerplate, and makes it easier to compose and bootstrap components directly.
Angular 15+ No NgModules Faster setup
standalone: true makes a component independent of any NgModule.CommonModule) are added via the component’s imports array.bootstrapApplication() instead of bootstrapModule().A standalone component is still declared with @Component, but it includes two important pieces:
standalone: true — marks the component as standalone.imports: [...] — declares all directives, pipes, and other components it needs.At the application entry point, you use bootstrapApplication() from @angular/platform-browser to start the app and optionally pass in a list of standalone components and providers.
// home.component.ts - standalone Home component
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
@Component({
selector: 'app-home',
standalone: true,
imports: [CommonModule],
template: '<h2>Welcome to Home</h2>'
})
export class HomeComponent { }
This creates a standalone component with the selector app-home. It:
CommonModule so you can access common directives like *ngIf and *ngFor.Welcome to Home.bootstrapApplication
// main.ts - bootstrapping the Angular app with standalone components
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import { HomeComponent } from './app/home/home.component';
bootstrapApplication(AppComponent, {
providers: [],
imports: [HomeComponent]
});
bootstrapApplication(AppComponent, ...) starts the Angular app using AppComponent as the root.HomeComponent is registered in the imports array, so it can be used inside AppComponent's template.<app-home> you’ll see: “Welcome to Home”.AppModule, reducing boilerplate and improving clarity.standalone: true makes the component independent of NgModules.imports array.bootstrapApplication directly bootstraps components without wrapping them in a module.AboutComponent that shows a short description of your app and display it inside AppComponent.ContactComponent) and import it into AboutComponent.