LearnThatStack Ace your next interview

Angular

Angular 20 to 22, standalone components and signals Checked Oct 2026 110 code snippets

The model

  • An app is a tree of components. Each one is a TypeScript class plus an HTML template, and it is standalone by default since Angular 19.
  • Bindings link the class and its template. {{ }} and [prop] send values to the template, (event) calls the class, and [( )] does both.
  • A class asks for a service with inject(). Dependency injection finds it in the nearest injector, or in a parent up to the root.
  • Change detection compares each binding with its last value and patches the DOM. Apps are zoneless by default since Angular 21, so only an event, a signal change or markForCheck() starts a check.
  • Observables carry async streams, such as HTTP responses, and run only once you subscribe. Signals hold state that you read by calling them, as in count().
DOMthe pageTemplatebindingsComponent classfields, signalsAngularchange detectionEVENT(click) runs a methodSTATEcount.set(1) notifiesCHECKcompare bindingsRENDERpatch what changed
Read top to bottom. An event or a signal update tells Angular to check. It compares each binding with its last value and patches only what changed.

Components & templates

the parts of an app, bindings and pipes

Angular's building blocks

Name the building blocksComponents, plus services, directives, pipes, guards and interceptors.
Say if Angular is a frameworkYes. It calls your code, which is inversion of control.
Say why Angular uses TypeScriptThe compiler catches type errors before the code runs.

Control flow & directives

show, repeat and project markup

Inputs, outputs & lifecycle

passing data and timing your code

Lifecycle hooks in order

ngOnChanges(changes)first, then on each input changengOnInit()once, inputs are setngDoCheck()every check, keep it cheapngAfterContentInit()once, projected content readyngAfterContentChecked()after every content checkngAfterViewInit()once, view children readyngAfterViewChecked()after every view checkngOnDestroy()once, clean up

TrapChanging bound state in ngAfterViewInit throws ExpressionChangedAfterItHasBeenChecked in development.

Services & DI

shared logic, supplied by Angular

Where Angular finds a provider

Say how Angular resolves a dependencyNearest injector first, then up to the root.
Give each component its own instanceproviders: [CartStore]Its children share it.
Provide it in an NgModuleEager modules share one instance. A lazy module gets its own.

TipprovidedIn: 'root' is tree-shakable. A class in a providers array always ships in the bundle.

Routing & lazy loading

pages, parameters and code loaded later

Routes and parameters

Map a path to a component{ path: 'user/:id', component: User }Put the ** wildcard last.
Register the routesprovideRouter(routes)NgModule apps use RouterModule.forRoot().
Read :idroute.snapshot.paramMap.get('id')Or subscribe to paramMap.
Read a query parametersnapshot.queryParamMap.get('q')It holds options, like a filter.

Guards and resolvers

Block a route unless signed incanActivate: [authGuard]
Name the guard typescanActivate, canActivateChild, canDeactivate and canMatch. Each returns a boolean or a UrlTree.
Load data before the route opensresolve: { item: itemResolver }

TrapNavigation waits for every resolver. Keep resolvers for small data the page can't render without.

Lazy routes and @defer

Lazy load one pageloadComponent: () => import('./admin')
Lazy load a set of child routesloadChildren: () => import('./shop.routes')Both need a default export, or a .then() that picks the export.
Lazy load part of a template@defer (on viewport) { }@placeholder { }

TrapDeferred components must be standalone and unused elsewhere in the file, or the build can't split them.

Forms

template-driven, reactive and validation

Template-driven or reactive

Pick a kind of formTemplate-driven for simple forms. Reactive for complex forms and easy testing.
Bind an input both ways[(ngModel)]="name"Short for [ngModel] plus (ngModelChange).
Define a reactive form in the classfb.group({ name: [''] })[formGroup]="form"
Build a form on signalsSignal Forms, from @angular/forms/signals. Stable since 22.
Build a form from field metadataA service builds a FormGroup from the field list.

HTTP & RxJS

call APIs and work with streams

Errors, loading and interceptors

Retry, then handle the failureretry(3)catchError(handle)Retry only idempotent requests, which are safe to repeat.
Catch every uncaught error{ provide: ErrorHandler, useClass: Log }
Stop the spinner on success or failurefinalize(() => loading.set(false))
Run code on every requestwithInterceptors([auth])
Add a header to a requestreq.clone({ setHeaders })Requests are immutable, so change a copy.

TrapOne shared boolean breaks when requests overlap. Keep a counter, often in an interceptor.

Observables, Promises and Subjects

Tell an Observable from a PromiseLazy, many values, and you can cancel it. A Promise is eager and gives one value.
Send events to subscribersnew Subject<void>()A late subscriber gets only new values.
Hold state with a current valuenew BehaviorSubject(0)A new subscriber gets the latest value at once.
Replay recent values to late subscribersnew ReplaySubject(2)

switchMap, mergeMap, concatMap, exhaustMap

sourceabswitchMapabmergeMapabconcatMapabexhaustMapatime

Value b arrives while a's request still runs. switchMap cancels a, mergeMap runs both, concatMap queues b, and exhaustMap drops b.

Search as the user typesswitchMap(q => search(q))
Save edits in orderconcatMap(x => save(x))
Ignore a second login clickexhaustMap(c => login(c))
Run requests in parallel, 3 at a timemergeMap(id => load(id), 3)

TrapDon't use switchMap for writes. Cancelling a request doesn't undo it on the server.

Signals & change detection

how and when the view updates

How a check starts

Say what Zone.js doesIt patches events, timers and HTTP, so any async task starts a check.
Say what starts a check without Zone.jsAn event, a signal change or markForCheck(). The default since 21.
Check this component nowcdr.detectChanges()It checks its children too.
Queue it for the next checkcdr.markForCheck()It marks the path up to the root.

TrapIn a zoneless app, zone.run() schedules no check. Update a signal or call markForCheck() instead.

CLI, build & test

the ng tool, builds and tests

The CLI, AOT and Ivy

Create a project and run itng new my-appng serve
Generate a component or a serviceng g c user-cardng g s data
Build for productionng build
Tell AOT from JITAhead-of-time compiles in the build, the default. Just-in-time compiles in the browser.
Name the compiler and rendererIvy. It's the only engine since Angular 13, replacing View Engine.

TipAOT ships no compiler, catches binding errors in the build and blocks template injection.

Environments, builders and schematics

Set values per environmentng generate environmentsIt sets up fileReplacements.
Name the default builder (17+)@angular/build:application
Write a custom buildercreateBuilder(fn)
Write your own generatorA schematic. It returns a Rule that changes a virtual file Tree.

Unit and end-to-end tests

Create the component, then update the DOMTestBed.createComponent(Card)fixture.detectChanges()
Set an inputcomponentRef.setInput('x', 1)
Test an outputSubscribe to it, trigger the action, and check the value.
Name the default test runner (21+)Vitest in new projects. Karma is still supported.
Run end-to-end testsng e2eIt offers Cypress, Playwright or WebdriverIO. Protractor is deprecated.

SSR, i18n & security

server rendering, translation and safety

Auth, XSRF and secrets

Keep a token away from XSSUse an httpOnly cookie. Any script can read localStorage.
Protect cookie requests from XSRFCross-site request forgery. HttpClient copies the XSRF-TOKEN cookie into a header.
Keep an API key secretKeep it on the server. Everything in the bundle is public.

TrapGuards only shape the UI. The server must check the token and the role on every request.

Found this useful? Pass it on.
Pro · $10/mo

This sheet stays free. With Pro, you can:

  • Every answer on this sheet. Read the full answer to all 95 questions it links, not just the 13 free ones.
  • My sheet. The cards you star and the ones you miss in Quiz me, from every sheet, on one page to quiz and print.
  • PDFs. Download this sheet and My sheet, laid out for A4, with every question a link to its answer.
  • The rest of Pro. Every answer in the question library, and 1,000 AI credits a month.