Skip to content
Tutorials Center
My learning

Topics

Lesson 73 of 74 ยท Practice and Review

Angular Interview Questions

40 Angular interview questions with concise answers, from components and signals to DI, change detection, RxJS, routing, forms and performance, with two runnable examples.

An Angular interview rarely checks whether you can recite the API. It checks whether you hold a correct mental model: what a component is made of, how data flows through a template, what makes the screen update, who creates a service, and when an observable is the right tool. The 40 questions below are grouped by topic and ordered roughly from beginner to senior. Each answer is short enough to say out loud in under a minute, and points to the lesson that explains it in depth.

How to use this page:

  • Do not memorize sentences. Read the question, answer it aloud in your own words, then compare. The bold phrases are the points interviewers listen for.
  • Know the version. This page targets modern Angular (20 and later): standalone components, signals, @if/@for, inject(). If a question mentions NgModule, *ngIf or @Input(), say that it exists in older code and what replaces it.
  • Expect follow-ups. "Why?" and "what breaks if...?" are the real questions. Where a common follow-up exists, it is in the answer.

Real Angular vs stand-in. Angular itself needs its compiler and CLI, which this site cannot run, so everything that imports from @angular/* stays read-only. The two runnable examples are small TypeScript models of the ideas behind questions 12 and 36. They are teaching stand-ins, not Angular's source or RxJS.

Fundamentals

1. What is Angular, and how does it differ from React?

Angular is a batteries-included framework written in TypeScript: components and templates, dependency injection, a router, forms, an HTTP client, testing tools and a CLI all ship together and are versioned together. React is a library for the view layer, and you pick the rest. Angular trades flexibility for consistency. See What Is Angular?.

2. What is the difference between a component, a directive, a pipe and a service?

A component is a directive with a template: it owns a piece of the screen. An attribute or structural directive changes behavior of an existing element without a template. A pipe transforms a value inside a template expression. A service is a plain class, usually created by dependency injection, that holds logic or state shared between components. See Your First Component, Directives, Pipes.

3. What are standalone components, and what happened to NgModules?

A standalone component declares what it uses in its own imports array, so it needs no NgModule. Standalone is the default in current Angular (the standalone: true flag is implied), and apps start with bootstrapApplication and an ApplicationConfig. NgModule still works and appears in older code, but new code does not need it. See Setup and the Angular CLI.

4. What kinds of data binding does a template support?

Four: interpolation {{ value }}, property binding [prop]="expr" (also [attr.x], [class.x], [style.x]), event binding (click)="handler($event)", and two-way binding [(prop)]="state", which is sugar for a property binding plus a propChange event. See Interpolation, Property binding, Event binding, Two-way binding.

5. How do @if and @for differ from *ngIf and *ngFor, and why does @for require track?

The built-in control flow blocks are part of the template syntax, need no imports, and compile to tighter code than the directives. @for requires track so Angular knows each item's identity and can move, keep or remove DOM nodes instead of re-creating them. Track by a stable id, not by the object itself or the index in reorderable lists. @empty handles the zero-item case. See Control Flow.

6. What is the difference between pure and impure pipes?

A pure pipe (the default) runs only when its input value or arguments change identity, so it is cheap. An impure pipe (pure: false) runs on every change detection pass and can be expensive. async is impure by design because it must watch an observable. Mutating an array in place will not re-run a pure pipe that receives it. See Pipes.

Components

7. How do components communicate with each other?

Parent to child through inputs (input(), input.required()), child to parent through outputs (output()), and two-way through model(). Unrelated components share a service (often holding signals). Data flows down, events flow up, which keeps the direction of change easy to follow. See Inputs and Outputs and State Management with Signals and Services.

8. What is content projection?

It lets a parent put markup between a component's tags and the component decide where it appears, using <ng-content>. With select you can define several named slots. It is the Angular way to build wrappers such as cards and dialogs without passing HTML through inputs. See Content Projection.

9. Name the lifecycle hooks and their order.

For one component: constructor, ngOnChanges (inputs changed), ngOnInit, ngDoCheck, ngAfterContentInit, ngAfterContentChecked, ngAfterViewInit, ngAfterViewChecked, and finally ngOnDestroy. Do setup that needs inputs in ngOnInit, clean up in ngOnDestroy (or with DestroyRef), and use afterNextRender for DOM work that only makes sense in a browser. See Lifecycle Hooks and afterNextRender.

10. What is view encapsulation?

It controls how a component's styles are scoped. Emulated (the default) adds generated attributes to elements and selectors so styles do not leak out. ShadowDom uses the browser's shadow DOM. None makes styles global. ::ng-deep pierces encapsulation and is discouraged. See Styling and Encapsulation.

11. How do you access a child element or component from the class?

Give it a template reference (#box) and use the signal query viewChild('box') (or viewChildren, contentChild). The result is undefined until the view exists, so read it inside an effect or after render, not in the constructor. Prefer inputs and outputs for data and queries only when you really need the instance or element. See Template Refs and View Queries.

Signals

12. What is a signal, and how does Angular know what to update?

A signal is a reactive value container: you read it by calling it, count(), and change it with set or update. While a template, computed or effect runs, every signal it reads is recorded as a dependency, so a change notifies exactly the consumers that read it. Change is detected with Object.is, so you replace arrays and objects instead of mutating them. The example shows both sides. See Signals.

TypeScript Stand-in: a signal ignores mutation, not replacement

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

13. When do you use signal, computed and effect?

signal for state you set. computed for derived values: lazy, memoized and read-only. effect for side effects outside the signal graph, such as logging, syncing to localStorage or calling a non-Angular library. If a value can be calculated from other signals, it must be a computed, never a second signal updated by an effect. See Signals and Signals in Components.

14. What are the common mistakes with effect?

Using it to copy state from one signal to another (use computed or linkedSignal), writing signals inside it so changes chain and loop, creating it outside an injection context, and expecting it to run synchronously after set. Effects are scheduled and batched by Angular. Use untracked to read something without making it a dependency. See Signals and Common Mistakes.

15. What does linkedSignal give you that computed does not?

A linkedSignal is derived but writable: it resets to a value computed from a source signal whenever the source changes, yet the user can set it in between. The classic case is a selected option that resets to the first item when the list changes. A computed cannot be written at all. See linkedSignal, resource and httpResource.

16. What is resource?

resource loads asynchronous data that depends on signals. You give it a params source and a loader; when the params change, it cancels the previous load and starts a new one, and exposes value, status, error and isLoading as signals. httpResource is the HttpClient-based variant. Check the API status for your version, because these APIs matured over several releases. See linkedSignal, resource and httpResource.

17. Signals or RxJS: how do you choose?

Use signals for state: a value that always exists and is read synchronously in templates. Use RxJS for streams of events over time: debouncing, cancellation, retries, combining sources, WebSockets. They interoperate: toSignal turns an observable into a signal, and toObservable does the reverse. See Signals and RxJS Interop.

Change detection

18. How does default change detection work, and what is Zone.js for?

Zone.js patches async APIs (events, timers, promises) so Angular is told when something might have changed. It then walks the component tree from the root, re-evaluating every template binding and updating the DOM where a value differs. It is simple and correct, but it checks everything on every event. See Change Detection, OnPush and Zoneless.

flowchart TD
  E["Event, timer or promise"] --> Z["Zone.js notifies Angular"]
  Z --> D{"Component uses<br/>OnPush?"}
  D -- "No" --> C["Check it and its children"]
  D -- "Yes" --> F{"Marked dirty?<br/>(input change, event,<br/>signal read in template)"}
  F -- "Yes" --> C
  F -- "No" --> S["Skip this subtree"]

Default components are always checked; OnPush components are checked only when marked dirty.

19. What does OnPush do, and what makes an OnPush component update?

ChangeDetectionStrategy.OnPush makes Angular skip a component until it is marked dirty. That happens when an input's reference changes, when an event handler in its template (or a child's) fires, when a signal read in its template changes, when the async pipe receives a value, or when you call markForCheck(). Immutable updates and signals make OnPush the safe default. See Change Detection.

20. What is zoneless change detection?

With provideZonelessChangeDetection() Angular does not load Zone.js and relies on explicit notifications: signals, events, markForCheck, async pipe and a few others schedule the next update. It means smaller bundles and fewer needless checks, but code that mutates plain fields and expects Angular to notice will stop updating. Check the status for your version before adopting it. See Change Detection.

21. What is ExpressionChangedAfterItHasBeenCheckedError?

In development mode Angular re-checks every binding after a pass to confirm nothing changed. If a value changed during the pass (for example a child sets a parent's field in a hook), the two reads differ and Angular throws. The fix is to restructure data flow so state is settled before it is read, using signals or computed, not to hide it with setTimeout. See Common Mistakes.

Dependency injection

22. What is dependency injection and why does Angular use it?

A class asks for what it needs (inject(HttpClient)) instead of constructing it. Angular's injector finds or creates the instance. This decouples consumers from implementations, so tests can swap a fake, and it gives you one place to control lifetime and sharing. See Services and Dependency Injection.

23. What does providedIn: 'root' mean, and inject() versus constructor injection?

@Injectable({ providedIn: 'root' }) registers the service in the application-wide injector as a singleton and makes it tree-shakable if nobody uses it. inject(Service) works in a field initializer or constructor (an injection context), is easy to use in functions such as guards and interceptors, and avoids long constructor parameter lists. Constructor injection still works. See Services and Dependency Injection.

24. Explain the injector hierarchy.

Injectors form a tree: the environment injector (root, plus those created for lazy routes), and the element injector tree that follows the component tree. A lookup starts at the requesting element and walks up until it finds a provider. A service listed in a component's providers gets a fresh instance per component instance, and its children share it. See Providers, InjectionToken and Scopes.

25. What is an InjectionToken, and why do you need one?

Interfaces vanish at runtime, so you cannot inject by interface. An InjectionToken<T> is a runtime key with a type attached, used for configuration objects, feature flags and abstractions. It can have a factory for a default value, and with multi: true several providers add to one array. See Providers, InjectionToken and Scopes.

26. What do useClass, useValue, useFactory and useExisting do?

useClass instantiates a different class for the token (swap an implementation). useValue provides a ready-made value. useFactory runs a function, which can itself call inject. useExisting makes a token an alias of another provider, so both resolve to the same instance. See Providers, InjectionToken and Scopes.

Routing

27. How does lazy loading work, and why does it matter?

With loadComponent or loadChildren and a dynamic import(), the build splits that code into a separate chunk that the browser downloads when the user first navigates there. The initial bundle shrinks, so the first load is faster. Preloading strategies can fetch chunks in idle time. See Child Routes and Lazy Loading.

28. What are functional guards, and what can they return?

A guard is a function (CanActivateFn, CanMatchFn, CanDeactivateFn) that runs inject() for what it needs and returns a boolean, a UrlTree (redirect), or a promise or observable of those. canMatch decides whether a route can be matched at all, which also stops the lazy chunk from loading. Guards are UX, not security: the server must enforce access. See Guards, Resolvers and Router Events.

29. What is a resolver, and how do route inputs help?

A ResolveFn loads data before the route activates, so the component starts with it. With withComponentInputBinding(), route params, query params and resolved data arrive as component inputs, so the component does not need ActivatedRoute. Resolvers delay navigation, so many apps load in the component with a loading state instead. See Route Parameters and Navigation.

30. How do you read route parameters and navigate in code?

Declare path: 'users/:id' and read it as an input (with input binding), from ActivatedRoute.paramMap, or the snapshot. Navigate with router.navigate(['/users', id], { queryParams: { tab: 'info' } }) or a routerLink. Reusing a component for a new id does not re-create it, so react to the changing param (signal input or observable), not just ngOnInit. See Route Parameters and Navigation.

Forms

31. Template-driven or reactive forms: which and when?

Template-driven forms (ngModel) put the logic in the template and suit small, simple forms. Reactive forms build a FormGroup tree in the class: explicit, typed, easy to test and to build dynamically. Use reactive forms for anything non-trivial. See Template-Driven Forms and Reactive Forms.

32. How do you write a custom validator, including a cross-field one?

A validator is a function that takes a control and returns null (valid) or an errors object such as { tooShort: true }. For cross-field rules, attach the validator to the parent group and read the child controls. Async validators return an observable or promise and run only when the sync ones pass. See Validation and Custom Validators.

33. What is a ControlValueAccessor?

The bridge between a form control and a custom component. It implements writeValue (model to view), registerOnChange and registerOnTouched (view to model), and optionally setDisabledState, and is provided under NG_VALUE_ACCESSOR. After that, your component works with formControlName and ngModel like a native input. See Dynamic Forms and Custom Form Controls.

34. What are signal forms?

A newer, signal-based forms API where the form state is a signal tree. It was introduced as experimental, so be honest in an interview: say what you know of the idea, that the API may still change, and that production apps today mostly use reactive forms. Check the docs for the current status. See Signal Forms.

RxJS and HTTP

35. How is an Observable different from a Promise?

A promise is eager, resolves once, and cannot be cancelled. An observable is usually lazy (nothing runs until you subscribe), can emit many values, can be unsubscribed, and composes with operators. HttpClient returns observables that emit once and complete. See RxJS Essentials.

36. What is the difference between switchMap, mergeMap, concatMap and exhaustMap?

All map each value to an inner observable. switchMap cancels the previous inner one (search-as-you-type). mergeMap runs them in parallel. concatMap queues them in order (saving edits). exhaustMap ignores new values while one is running (a submit button). The model below applies the four scheduling rules to three requests that start at times 0, 10 and 20 and each take 30 units. See RxJS Operators.

TypeScript Stand-in: four flattening strategies on a virtual clock

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

37. How do you avoid memory leaks with subscriptions?

Prefer not to subscribe by hand: use the async pipe or toSignal, which clean up automatically. When you must subscribe, end the stream with takeUntilDestroyed() (inside an injection context, or pass a DestroyRef). Long-lived streams such as interval, WebSockets and store observables are the usual leak sources; HttpClient completes by itself. See RxJS Operators and Signals and RxJS Interop.

38. What is an HTTP interceptor, and in what order do they run?

A functional interceptor, registered with provideHttpClient(withInterceptors([a, b])), sees each request and can change it (requests are immutable, so you clone them) and the response stream. Requests pass through the array in order, responses come back in reverse. Typical uses are auth headers, error mapping, retry and logging. See HTTP Interceptors.

Performance and architecture

39. What are SSR, hydration and deferrable views?

SSR renders HTML on the server for faster first paint and SEO; prerendering does it at build time. Hydration lets the browser reuse that HTML instead of rebuilding it, and incremental hydration can postpone it for parts of the page. @defer lazily loads a block of the template on a trigger (viewport, idle, interaction, timer), with @placeholder, @loading and @error states. Browser-only APIs must be guarded when code also runs on the server. See SSR, Hydration and Prerendering and Deferrable Views.

40. How would you speed up a slow Angular app?

Measure first: the Angular DevTools profiler, the browser performance panel and bundle analysis. Then the usual wins: lazy-load routes and @defer heavy blocks, use OnPush and signals so less is checked, add track to every @for, keep expensive work out of template function calls (use computed or pure pipes), virtualize long lists, optimize images with NgOptimizedImage, and enforce bundle budgets in CI. See Performance Tuning.

Architecture and tooling

41. What architecture pattern does Angular follow: MVC or MVVM?

Angular is component-based, and its component structure maps most closely to MVVM. The model is your data and services, the view is the template, and the component class acts as the view-model: it exposes state and handlers, and bindings keep the template in step with it. AngularJS, the first version, was usually described as MVC with controllers and $scope. The benefits are testable logic and reusable components; the costs are a learning curve and more structure than a small page needs.

42. What is the difference between JIT and AOT compilation?

AOT (ahead of time) compiles templates during the build, so the browser receives ready-to-run code. It is the default today and gives faster startup, template errors at build time and smaller bundles. JIT (just in time) compiled templates in the browser at run time; it needs the compiler shipped to users and is only used in special cases such as some test setups. See How Angular Works.

43. What are the main benefits of the Angular CLI?

One tool covers the whole workflow: ng new creates a project, ng generate scaffolds components, services, guards and pipes with correct wiring, ng serve runs a dev server with live reload, ng test and ng build run tests and production builds (minified, tree-shaken, with budgets), and ng update migrates code between versions. The workspace is configured in angular.json. See Setup and the Angular CLI.

44. What is the difference between @Injectable and @Inject?

@Injectable() marks a class as something the injector can create (and says where it is provided). @Inject(TOKEN) marks a constructor parameter and names the token to inject, which you need for an InjectionToken. New code uses the inject() function instead of @Inject. See Providers, InjectionToken and Scopes.

45. What is the difference between a BehaviorSubject and a plain Observable?

A plain Observable is a cold, read-only stream: each subscriber normally triggers its own execution and there is no "current value." A BehaviorSubject is both an observer and an observable: you push values with next(), it requires an initial value, it holds the latest value and gives it to every new subscriber immediately, and you can read it synchronously with getValue() or .value. It is a common building block for shared state, though a signal is now the simpler choice. Expose it as asObservable() so outsiders cannot call next(). See RxJS Essentials.

46. Why do Angular apps use an NgModule less now, and what did it do?

An NgModule grouped declarations, imports, exports and providers so the compiler knew which components, directives and pipes a template could use. Standalone components list their own imports, so a module is rarely needed. It also differs from a JavaScript module: a JS module controls file-level scope and bundling, while an NgModule told the Angular compiler what is visible in templates. See NgModules and Legacy Angular Code.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A user mutates an array held in a signal with items().push('x'). What happens?

    Signals compare values with Object.is. Replace the array with a new one so the signal can notify its consumers.
  2. 2. Which operator should handle a search box where only the latest query matters?

    switchMap cancels the previous inner request when a new value arrives, so stale responses cannot overwrite newer ones.
  3. 3. Which of these marks an OnPush component as dirty?

    OnPush components are checked after an input reference change, an event from their template, a signal change they read, async pipe values or markForCheck.
  4. 4. Why can you not inject an interface in Angular?

    TypeScript interfaces do not exist in the compiled JavaScript. An InjectionToken is a runtime object that carries the type.
  5. 5. How should you fix ExpressionChangedAfterItHasBeenCheckedError?

    The error points at a real inconsistency in data flow. Hiding it with timers or forced checks treats the symptom.

Summary

  • Interviewers test mental models: component structure, data flow, what triggers an update, who owns a service, and when to use an observable.
  • Modern Angular means standalone components, signals for state, @if/@for control flow, inject() and functional guards and interceptors.
  • Signals for state, RxJS for streams over time, and the interop functions to bridge them.
  • OnPush plus signals plus track is the baseline for fast change detection; measure before optimizing.
  • Be honest about version and status: signal forms, resource and zoneless matured over several releases, so check the docs for the version you are asked about.

Next: Angular Cheat Sheet