On this page
Angular 21: the framework, CLI, and first project
What is Angular?
Angular is a complete framework for building web applications. Unlike libraries such as React or Vue, Angular includes everything you need: routing, forms, HTTP client, testing, SSR, and dependency injection.
In version 21, Angular has matured significantly:
- Standalone components by default (no NgModules)
- Signals as the primary reactive primitive
- New control flow in templates (
@if,@for,@switch) - SSR and pre-rendering built-in
- Zoneless change detection (experimental)
Installing Angular CLI
Angular CLI is the command-line tool for creating and managing projects:
# Install globally
npm install -g @angular/cli
# Verify the version
ng versionCreating a project
The ng new command generates a complete project with all configurations:
ng new my-first-appAngular 21 will ask you about:
- Style format (CSS, SCSS, etc.)
- SSR (Server-Side Rendering)
The generated structure includes:
my-first-app/
src/
app/
app.ts # Root component
app.routes.ts # Application routes
index.html # HTML entry point
main.ts # App bootstrap
styles.css # Global styles
angular.json # Project configuration
tsconfig.json # TypeScript configuration
package.json # DependenciesThe root component
Every Angular application has a root component (App). It is the entry point that contains the main layout and the <router-outlet> for rendering pages.
Essential CLI commands
| Command | Description |
|---|---|
ng serve |
Development server with HMR |
ng build |
Build for production |
ng generate component name |
Generate a component |
ng generate service name |
Generate a service |
ng test |
Run tests |
ng e2e |
End-to-end tests |
Angular vs other frameworks
| Feature | Angular | React | Vue |
|---|---|---|---|
| Type | Complete framework | Library | Progressive framework |
| Language | TypeScript required | JavaScript/TypeScript | JavaScript/TypeScript |
| Reactivity | Signals | useState/hooks | ref/reactive |
| Routing | Built-in | React Router (external) | Vue Router (external) |
| HTTP | Built-in HttpClient | fetch/axios (external) | fetch/axios (external) |
| DI | Built-in | Context API | provide/inject |
Angular 21 philosophy
Angular 21 follows the philosophy of simplicity without sacrificing power:
- Less boilerplate — No NgModules, no extra decorators
- Granular reactivity — Signals gradually replace Zone.js
- Performance by default — OnPush, lazy loading, built-in SSR
- Developer experience — Powerful CLI, clear error messages, fast HMR
Practice
- Create your first project: Run
ng new my-practicein the terminal and explore the generated file structure. Identify the root component and the routes file. - Modify the root component: Change the title in
app.tsand add a second navigation link in the template. Verify the changes withng serve. - Generate a component: Use
ng generate component greetingto create a new component and render it inside the root component's template.
In the next lesson, we will learn how to create standalone components, the fundamental building block of Angular.
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { RouterOutlet } from '@angular/router';
@Component({
selector: 'app-root',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [RouterOutlet],
template: `
<header>
<h1>{{ title }}</h1>
<nav>
<a routerLink="/">Home</a>
<a routerLink="/about">About</a>
</nav>
</header>
<main>
<router-outlet />
</main>
`,
styles: `
header {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
}
nav { display: flex; gap: 0.5rem; }
`,
})
export class App {
readonly title = 'My first Angular project';
}
Sign in to track your progress