Component Basics in Angular

From the Angular cheat sheet ยท Components ยท verified Jul 2026

Component Basics

Standalone components are the default in Angular 17+. NgModule is legacy.

typescript
// Standalone component (default in Angular 17+)
// Generate: ng generate component user-card --standalone
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';

@Component({
  selector: 'app-user-card',
  standalone: true,
  imports: [CommonModule],     // Import dependencies directly
  template: \`
    <div class="card">
      <h2>{{ name }}</h2>
      <p>{{ email }}</p>
    </div>
  \`,
  styles: [\`.card { padding: 1rem; }\`],
})
export class UserCardComponent {
  name = 'Alice';
  email = 'alice@example.com';
}

// Bootstrap a standalone app
// main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent);
๐Ÿ’ก Standalone is the default in Angular 17+ โ€” no AppModule needed
โšก Import dependencies directly in the component's `imports` array
๐Ÿ“Œ Bootstrap with bootstrapApplication() + provideX() helpers
๐Ÿ”ฅ ng generate @angular/core:standalone migrates legacy NgModule apps

More Angular tasks

Back to the full Angular cheat sheet