Setup and your first application
Ten minutes to a running application, then a careful walk through every generated file — because the ones people ignore are exactly the ones that cause trouble later.
Installing
node --version # 20 LTS or 22 — Angular 18 requires ≥ 18.19 npm install -g @angular/cli@18 ng version
npx @angular/cli@18 new orders-web works without a global install and pins
the version per project — which matters when you maintain several applications on
different Angular versions.
Generating the project
ng new orders-web \ --style=scss \ --routing \ --ssr=false \ --package-manager=npm cd orders-web ng serve --open
| Flag | Choose | Why |
|---|---|---|
--style | scss | Nesting and variables; you will want them by week two |
--routing | yes | Adds app.routes.ts — every real app needs it |
--ssr | no for now | Adds a Node server; enable later if you need SEO (chapter 12) |
--standalone | default since v17 | No NgModule scaffolding |
What was generated
orders-web
├── angular.json build/serve/test configuration — budgets live here
├── package.json
├── tsconfig.json strict mode, path aliases
├── public/ copied verbatim into the build output
└── src
├── index.html the only HTML page the server ever returns
├── main.ts bootstraps the application
├── styles.scss global styles
└── app
├── app.config.ts providers: router, http, interceptors
├── app.routes.ts route table
├── app.component.ts root component
└── app.component.html
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, appConfig)
.catch(err => console.error(err));
import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';
import { provideRouter, withComponentInputBinding } from '@angular/router';
import { provideHttpClient, withInterceptors, withFetch } from '@angular/common/http';
import { routes } from './app.routes';
import { authInterceptor } from './core/auth/auth.interceptor';
import { errorInterceptor } from './core/http/error.interceptor';
export const appConfig: ApplicationConfig = {
providers: [
// coalescing batches change detection across a burst of events
provideZoneChangeDetection({ eventCoalescing: true }),
provideRouter(
routes,
withComponentInputBinding(), // route params bind straight to input()s
),
provideHttpClient(
withFetch(), // uses fetch(); required for SSR streaming
withInterceptors([authInterceptor, errorInterceptor]),
),
],
};
This file is the single place that answers "what is switched on in this application?". Every chapter from here adds one line to it.
Your first component
ng generate component features/orders/order-list --inline-style # short form: ng g c features/orders/order-list
import { Component, signal } from '@angular/core';
import { CurrencyPipe, DatePipe } from '@angular/common';
interface Order {
id: number;
reference: string;
total: number;
status: 'PLACED' | 'PAID' | 'SHIPPED';
placedAt: string;
}
@Component({
selector: 'app-order-list',
standalone: true,
imports: [CurrencyPipe, DatePipe],
template: `
<h2>Orders</h2>
<table class="table">
<thead>
<tr><th>Reference</th><th>Placed</th><th>Total</th><th>Status</th></tr>
</thead>
<tbody>
@for (order of orders(); track order.id) {
<tr>
<td>{{ order.reference }}</td>
<td>{{ order.placedAt | date:'short' }}</td>
<td>{{ order.total | currency:'EUR' }}</td>
<td><span class="badge">{{ order.status }}</span></td>
</tr>
} @empty {
<tr><td colspan="4">No orders yet.</td></tr>
}
</tbody>
</table>
`,
styles: `
.table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .75rem; border-bottom: 1px solid #e5e7eb; }
`,
})
export class OrderListComponent {
readonly orders = signal<Order[]>([
{ id: 1, reference: 'ORD-1042', total: 128.00, status: 'PAID',
placedAt: '2026-08-14T10:12:00Z' },
{ id: 2, reference: 'ORD-1043', total: 42.50, status: 'PLACED',
placedAt: '2026-08-15T09:03:00Z' },
]);
}
import { Routes } from '@angular/router';
export const routes: Routes = [
{ path: '', redirectTo: 'orders', pathMatch: 'full' },
{
path: 'orders',
// lazily loaded: this component ships in its own JS chunk
loadComponent: () =>
import('./features/orders/order-list/order-list.component')
.then(m => m.OrderListComponent),
},
{ path: '**', loadComponent: () => import('./shared/not-found.component')
.then(m => m.NotFoundComponent) },
];
Talking to the backend in development
The dev server runs on :4200, the API on :8080. Calling it
directly triggers CORS. Proxy instead — then the browser only ever sees one origin, exactly
as in production.
{
"/api": {
"target": "http://localhost:8080",
"secure": false,
"changeOrigin": true,
"logLevel": "debug"
}
}
"serve": {
"options": {
"proxyConfig": "proxy.conf.json"
}
}
Now this.http.get('/api/orders') works in development and in production with
no environment switch and no CORS configuration at all.
Bundle budgets — set them on day one
"budgets": [
{ "type": "initial", "maximumWarning": "500kB", "maximumError": "1MB" },
{ "type": "anyComponentStyle","maximumWarning": "4kB", "maximumError": "8kB" }
]
Nobody notices 40 KB added in a pull request. Everybody notices 2 MB six months later, when it is twenty commits' worth of work to unwind. Make the build fail instead.
TypeScript strictness
{
"compilerOptions": {
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"angularCompilerOptions": {
"strictTemplates": true,
"strictInjectionParameters": true,
"typeCheckHostBindings": true
}
}
strictTemplates is the important one: it type-checks your HTML. Passing a
string where a component expects a number becomes a build error
instead of a runtime surprise. Never turn it off.
The CLI commands you will actually use
| Command | Does |
|---|---|
ng serve | Dev server with hot reload |
ng build | Production build into dist/ |
ng test | Unit tests |
ng generate c|s|d|p|g | Component, service, directive, pipe, guard |
ng update | Upgrades Angular and runs code migrations |
ng build --stats-json | Produces data for bundle analysis |
ng lint | ESLint, after ng add @angular-eslint/schematics |
ng update @angular/core@19 @angular/cli@19 rewrites your source for renamed
APIs automatically. Upgrade one major version at a time, commit between each, and the
whole thing is usually an afternoon.
Troubleshooting the first run
| Symptom | Cause | Fix |
|---|---|---|
'app-order-list' is not a known element | Component not in the parent's imports | Add it to the standalone component's imports array |
NG0201: No provider for HttpClient | provideHttpClient() missing | Add it to app.config.ts |
| Blank page, no errors | Route did not match | Check app.routes.ts and that <router-outlet> exists |
| CORS error in dev | Calling :8080 directly | Use the proxy config above |
NG0100: ExpressionChangedAfterItHasBeenChecked | Value mutated during change detection | Move the write into a signal or an event handler |
Why proxy /api in development rather than calling
http://localhost:8080 directly?
With a proxy the relative path /api/orders works unchanged in development
and in production, where nginx or the ingress performs the same routing. No CORS
configuration and no environment switching.