Frontend · Angular

Top 50 Angular Interview Questions & Answers for 2026

· 30 min read · Intervio Team

1. Core Architecture & Basics

Q1: What is Angular? How does it differ from AngularJS?

Angular is a TypeScript-based open-source framework built by Google for building single-page client applications. Unlike AngularJS (v1.x) which is MVC-based and uses JavaScript, Angular (v2+) is component-based, uses TypeScript, has hierarchical dependency injection, and utilizes a faster DOM rendering model.

Q2: Explain the main building blocks of an Angular application.

The core building blocks are:

  • Components: Define the UI and view logic.
  • Directives: Extend HTML structure and behavior.
  • Modules (NgModule): Group related components, directives, and services (Note: modern Angular uses Standalone Components instead).
  • Services & DI: Handle business logic and share data across components.

Q3: What are Standalone Components in Angular?

Introduced in Angular 14, standalone components, directives, and pipes allow you to build Angular apps without needing NgModule. They declare their own imports directly inside the @Component decorator, making code smaller, cleaner, and easier to lazy load.

Q4: What is Dependency Injection (DI) in Angular?

DI is a design pattern where a class requests dependencies from external sources rather than creating them itself. Angular has a hierarchical DI framework, which means dependencies can be scoped globally (provided in root), per module, or per component.

Q5: Explain the lifecycle hooks of an Angular component in sequence.

The hooks run in this order:

  1. ngOnChanges - Responds when input properties change.
  2. ngOnInit - Called once component is initialized.
  3. ngDoCheck - Custom change detection check.
  4. ngAfterContentInit - Component content projection initialized.
  5. ngAfterContentChecked - Content projection checked.
  6. ngAfterViewInit - Component views initialized.
  7. ngAfterViewChecked - Component views checked.
  8. ngOnDestroy - Called before component is destroyed.

Q6: What is the purpose of ngOnChanges and when does it trigger?

ngOnChanges is a lifecycle hook called before ngOnInit and whenever one or more data-bound input properties (@Input) change. It receives a SimpleChanges object containing current and previous values.

Q7: What is the difference between constructor and ngOnInit?

The constructor is a default TypeScript class method called when the class is instantiated. It should only be used for basic dependency injection. ngOnInit is an Angular lifecycle hook called after Angular has completed data binding and initialized the input properties, making it the proper place to trigger HTTP requests or initialization logic.

Q8: How does Angular handle Change Detection?

Angular scans the component tree from top to bottom checking for data model changes. It offers two change detection strategies: Default (re-checks everything whenever any event occurs) and OnPush (re-checks only when an input reference changes, an event triggers inside the component, or an observable template binding emits).

Q9: What is Zone.js and what role does it play in Angular change detection?

Zone.js is an execution context library that patches asynchronous operations (clicks, timeouts, HTTP calls) in the browser. It notifies Angular when an async task completes, triggering automatic change detection. Modern Angular versions support zone-less execution via Signals.

Q10: What is AoT compilation? How does it differ from JoT compilation?

AoT (Ahead-of-Time) compiles templates during the build process, capturing errors early and shrinking bundle sizes. JoT (Just-in-Time) compiles templates dynamically inside the user's browser, which causes a slower startup time. Production builds always use AoT.

Q11: What is the difference between markForCheck() and detectChanges() in ChangeDetectorRef?

detectChanges() forces Angular to run change detection immediately for the current component and its children. markForCheck() doesn't run change detection immediately; instead, it marks the current component and all its ancestors as "dirty" so they will be scanned in the next global change detection cycle (useful with OnPush).

Q12: What is ViewEncapsulation in Angular?

ViewEncapsulation defines how scoped component styles are packaged. It has three modes:

  • Emulated (Default): Scopes styles by adding unique attributes to DOM elements.
  • None: Component styles are injected globally and affect the whole app.
  • ShadowDom: Uses the browser's native Shadow DOM to completely isolate component styles.

Q13: What is the difference between ViewChild and ContentChild?

@ViewChild queries elements or child components that are defined directly inside the component's own template. @ContentChild queries elements or child components projected inside the component via <ng-content> content projection.

Q14: Explain the difference between ng-template, ng-container, and ng-content.

They serve different templating roles:

  • ng-template: Defines a template block that is not rendered on load, but can be instantiated dynamically (e.g. via *ngIfElse).
  • ng-container: A logical grouping element that doesn't render any wrapper tags in the output DOM (prevents layout styling pollution).
  • ng-content: Replaces itself with projected elements passed from parent tags (content projection).

Q15: What are Angular Schematics?

Schematics are a template-based code generator toolset. They power the Angular CLI commands (like ng generate component or ng add), allowing developers to automate boilerplate creation, run migrations, and transform code safely.

2. Directives, Pipes & Data Binding

Q16: What is the difference between Component, Structural, and Attribute directives?

Component directives are directives with templates. Structural directives modify the DOM layout by adding or removing elements (prefixed with an asterisk like *ngIf and *ngFor). Attribute directives change the appearance or behavior of an existing DOM element (like ngClass and ngStyle).

Q17: What is the difference between Promise and Observable in Angular?

A Promise handles a single event asynchronously and cannot be cancelled. An Observable handles a stream of multiple events over time, can be cancelled (unsubscribed), and supports powerful reactive operators like map, filter, and switchMap via RxJS.

Q18: How does Two-Way Data Binding work in Angular?

Two-way binding combines property binding (data flows model to view) and event binding (data flows view to model). It uses the banana-in-a-box syntax [(ngModel)] to automatically synchronize changes between the UI input and component properties.

Q19: What are Custom Pipes? How do you create one?

Custom pipes transform template data format. You create one by defining a class decorated with @Pipe, registering its name, and implementing the PipeTransform interface containing the transform() method.

Q20: What is the difference between pure and impure pipes?

Pure pipes are executed only when they detect a pure change in the input value (a change to a primitive type or reference). They are highly performant. Impure pipes run on every change detection cycle, regardless of whether the inputs changed, which can lead to performance bottlenecks if not managed carefully.

Q21: How do you communicate between parent and child components?

To send data from parent to child, use @Input() property bindings. To send data from child to parent, use @Output() event bindings coupled with an EventEmitter.

Q22: What is @ViewChild and @ViewChildren?

@ViewChild queries a single element or component instance inside the class template view. @ViewChildren queries multiple instances, returning them as a query list wrapper that stays updated dynamically.

Q23: What is Content Projection (<ng-content>)?

Content projection is a pattern where you insert HTML content from a parent template inside the child component layout. The child component uses the <ng-content> tag to act as a placeholder, rendering whatever elements the parent passes inside its tags.

Q224: What is the AsyncPipe? Why is it highly recommended?

The async pipe subscribes to an Observable or Promise directly inside the HTML template and returns the latest value. Crucially, it **automatically unsubscribes** when the component is destroyed, preventing memory leaks without needing manual cleanup code.

Q25: Explain the difference between template-driven and reactive forms.

Template-driven forms rely on HTML markup directives (using ngModel) and are easy to use for simple inputs. Reactive forms use explicit classes inside the component code (like FormGroup and FormControl), allowing for robust testing, custom sync/async validators, and dynamic inputs.

Q26: What is the ControlValueAccessor (CVA) interface? When do you use it?

CVA is an interface that acts as a bridge between Angular Form APIs and custom form controls in the DOM. Implement CVA when you want to build a reusable custom input component (like a custom toggle, rate star, or calendar component) that works seamlessly with formControlName or ngModel.

Q27: What is the difference between @HostListener and @HostBinding?

@HostListener is a decorator that listens to host DOM element events (like click, mouseover, or window resize) and binds them to component handler functions. @HostBinding is a decorator that binds a component host DOM property (like css class, style, or disabled attributes) directly to a class property value.

Q28: How do you handle HTTP caching in Angular?

HTTP caching in Angular is usually implemented using a custom HTTP Interceptor. The interceptor intercepts outgoing GET requests, checks if the response is cached in a Map, returns the cached response if available, or makes the network call and updates the cache.

Q29: Explain the Subject types in RxJS (Subject, BehaviorSubject, ReplaySubject, AsyncSubject).

They differ in cache and initial value characteristics:

  • Subject: No initial value or memory; only emits new values to subscribers.
  • BehaviorSubject: Requires an initial value and caches the latest value, immediately emitting it to new subscribers.
  • ReplaySubject: Caches a specified buffer number of values and replays them to new subscribers.
  • AsyncSubject: Only emits the last value (and closes) to subscribers when the execution completes.

Q30: How do you configure fallback routing in Angular?

Define a wildcard path matching ** as the very last route in your routes array. It should load a PageNotFoundComponent or redirect to home (e.g. { path: '**', redirectTo: '/404' }).

3. Advanced Concepts, Signals & RxJS

Q31: What are Angular Signals? Why are they a game changer?

Signals are a reactive state tracking mechanism introduced in Angular 16. Unlike RxJS, which propagates values through streams, Signals track exactly where a value is used in the UI, enabling fine-grained change detection without relying on Zone.js to scan the entire component tree.

Q32: Explain the computed() and effect() APIs in Signals.

computed() creates a read-only signal that derives its value from other signals and caches the result. effect() runs side-effect operations whenever the signals read inside it change.

Q33: How do you achieve Lazy Loading in Angular?

By using the loadComponent or loadChildren syntax in the route definitions. Angular will compile lazy loaded modules/components into separate chunks that are only loaded when the user navigates to that path.

Q34: What are Route Guards? List different types.

Route guards run logic before navigating to a route to determine if access is allowed. The main guard interfaces are:

  • CanActivate - Controls if a route can be loaded.
  • CanActivateChild - Controls if children of a route can be loaded.
  • CanDeactivate - Determines if a user can leave the current route.
  • Resolve - Prefetches API data before loading the route component.

Q35: Explain switchMap, mergeMap, concatMap, and exhaustMap in RxJS.

These flattening operators map values to inner Observables differently:

  • switchMap - Cancels the current inner subscription whenever a new outer value emits (best for searches).
  • mergeMap - Resolves all inner subscriptions concurrently in parallel.
  • concatMap - Resolves inner subscriptions sequentially in order.
  • exhaustMap - Ignores incoming outer values until the active inner subscription completes.

Q36: What is Server-Side Rendering (SSR) in Angular?

SSR pre-renders Angular components on the server into static HTML before sending them to the browser. This dramatically improves initial load performance, Core Web Vitals scores, and crawlers' SEO accessibility.

Q37: How do you optimize Angular application performance?

Key optimizations include:

  • Using ChangeDetectionStrategy.OnPush.
  • Lazy loading routing modules and components.
  • Implementing trackBy functions for lists.
  • Utilizing the async pipe to avoid subscription memory leaks.
  • Deferring third-party scripts and utilizing image lazy loading.

Q38: What is trackBy in *ngFor (and the new @for syntax)?

trackBy returns a unique identifier (like an item ID) to Angular. When a list changes, instead of destroying and re-creating the entire DOM tree, Angular uses the ID to only re-render the specific items that changed, boosting performance. Modern Angular handles this natively via the @for (item of items; track item.id) syntax.

Q39: What is the interceptor pattern in Angular HTTP client?

HTTP Interceptors intercept incoming requests or outgoing responses globally. They are commonly used to attach authorization headers (like Bearer tokens), handle global API failures, trace request logs, or inject cache layers.

Q40: What are Standalone APIs for routing and HTTP client setup?

With Standalone configurations, you set up core configurations globally inside bootstrapApplication using helper functions: provideRouter() to declare application routing trees, and provideHttpClient() to bootstrap client dependencies.

Q41: What is Zone-less Angular, and how do you enable it in Angular 18+?

Zone-less Angular runs applications without relying on the Zone.js monkey-patch library. Since change detection is natively driven by Signals, you remove Zone.js from compilation to reduce bundle size and call provideExperimentalZonelessChangeDetection() in global providers.

Q42: How do you handle error handling globally in Angular?

Provide a custom class that implements the ErrorHandler interface containing the handleError(error: any) method. Register it globally in the bootstrap providers (e.g. { provide: ErrorHandler, useClass: GlobalErrorHandler }) to catch and log runtime errors to logging backends.

Q43: What are dynamic components? How do you load them programmatically?

Dynamic components are instantiated at runtime. You load them using ViewContainerRef inside your component class by calling its createComponent(ComponentClass) method, which inserts the component dynamically without declaring template tags.

Q44: What is route preloading in Angular?

Route preloading loads lazy loaded router module chunks in the background *after* the initial main bundle has finished loading. You enable it in global routing configuration by passing the PreloadAllModules strategy: provideRouter(routes, withPreloading(PreloadAllModules)).

Q45: Explain forkJoin, combineLatest, zip, and withLatestFrom in RxJS.

These are combination operators:

  • forkJoin: Emits when all source observables complete, returning their final values (equivalent to Promise.all).
  • combineLatest: Emits a value whenever any source observable emits, returning the latest values from each.
  • zip: Pairs values from sources by index and emits them together as arrays.
  • withLatestFrom: Combines the primary source emission with the latest values from secondary observables.

Q46: How do you optimize web accessibility (a11y) in Angular?

Use semantic HTML5 elements, implement proper ARIA roles and labels dynamically, utilize the Angular CDK A11y module for focus trap control, manage keyboard focus using skip-links, and ensure contrast and screen reader accessibility guidelines are tested.

Q47: What is the new control flow syntax in Angular 17+?

Angular 17 introduced a new built-in template control flow syntax replacing directives. It uses @if, @else, @for, and @switch blocks. This syntax compiles into faster code, requires no NgFor/NgIf template imports, and supports clean default fallbacks (like @empty inside loops).

Q48: How do you write unit tests for Angular components and services?

Use the TestBed API to configure compilation modules. Test services by injecting them, and test components by creating a component fixture (e.g. TestBed.createComponent()), querying its elements via debugElement.query(), and validating DOM expectations using Jasmine/Jest matchers.

Q49: What is NgRx? Why and when should you use it?

NgRx is a Redux-based state management library for Angular. Use it in complex, large-scale applications with shared state, concurrent users, and complex data flows. It forces state changes to be unidirectional via Actions, Reducers, Selectors, and Effects, making app state highly predictable.

Q50: How does Angular compare to React and Next.js in 2026?

Angular is a full-featured batteries-included framework that comes with routing, form validation, and HTTP clients built-in, while React is only a UI library that requires external tooling. Next.js bridges this gap for React by providing routing and SSR. With Signals and Standalone APIs, Modern Angular matches Next.js developer velocity and performance while retaining strict TypeScript architecture.