Skip to main content

Mid Angular Interview Questions

Curated Mid-level Angular interview questions for developers targeting mid positions. 39 questions available.

Last updated:

Angular Interview Questions & Answers

Skip to Questions

Welcome to our comprehensive collection of Angular interview questions and answers. This page contains expertly curated interview questions covering all aspects of Angular, from fundamental concepts to advanced topics. Whether you're preparing for an entry-level position or a senior role, you'll find questions tailored to your experience level.

Our Angular interview questions are designed to help you:

  • Understand core concepts and best practices in Angular
  • Prepare for technical interviews at all experience levels
  • Master both theoretical knowledge and practical application
  • Build confidence for your next Angular interview

Each question includes detailed answers and explanations to help you understand not just what the answer is, but why it's correct. We cover topics ranging from basic Angular concepts to advanced scenarios that you might encounter in senior-level interviews.

Use the filters below to find questions by difficulty level (Entry, Junior, Mid, Senior, Expert) or focus specifically on code challenges. Each question is carefully crafted to reflect real-world interview scenarios you'll encounter at top tech companies, startups, and MNCs.

Questions

39 questions
Q1:

What problem does NgRx solve, and when should it be used instead of simple services?

Mid

Answer

NgRx solves complex application state management problems, especially in large apps where multiple components need shared state.

You should use NgRx when many components read and update global state, require time-travel debugging, offline caching, immutability, or predictable unidirectional data flow.

Small apps do not need NgRx; services or BehaviorSubjects are sufficient.

Quick Summary: NgRx solves complex shared state management. Use it when: multiple components need the same state, state changes trigger complex side effects, you need time-travel debugging, or state logic is hard to test in services. For simple apps, services with BehaviorSubjects are sufficient. NgRx adds boilerplate - only adopt when service-based state management becomes unmanageable.
Q2:

Explain the core building blocks of NgRx Store and how they work together.

Mid

Answer

NgRx uses a predictable data flow:

  • Actions: Describe events
  • Reducers: Update state immutably
  • Store: Holds global state
  • Selectors: Retrieve computed data
  • Effects: Handle async operations

The flow is: Actions ? Reducers ? Store ? Selectors ? Components ? Effects ? new Actions.

Quick Summary: NgRx building blocks: Store (single source of truth - the state tree), Actions (events describing what happened), Reducers (pure functions that compute new state from action + previous state), Selectors (pure functions to derive/slice state), Effects (handle side effects like HTTP calls, triggered by actions, dispatch new actions). Unidirectional data flow: component dispatches action -> reducer updates store -> component reads selector.
Q3:

What is the difference between Reactive Forms and Template-Driven Forms?

Mid

Answer

Reactive Forms use TypeScript classes for form control, offer better scalability, testing, dynamic fields, and are suitable for enterprise use.

Template-Driven Forms rely on HTML templates, good for small simple forms but less testable and harder to scale.

Quick Summary: Reactive Forms: FormGroup/FormControl defined in TypeScript, more control, easier to test, dynamic forms, better for complex validation. Template-Driven: uses ngModel in template, less code for simple forms, harder to test, validation in template. Reactive forms scale better for complex scenarios. Template-driven forms are fine for simple cases. Reactive is the recommended approach for enterprise Angular apps.
Q4:

How do Angular Guards work internally and what types exist?

Mid

Answer

Guards run before route activation to allow or block navigation.

Types include: CanActivate, CanDeactivate, CanLoad, CanActivateChild, and Resolve.

They handle security, data preloading, navigation rules, and preventing access to invalid or unauthorized pages.

Quick Summary: Guards are services implementing guard interfaces. Angular Router calls them before activating/deactivating routes. CanActivate: blocks unauthenticated access. CanDeactivate: warns about unsaved changes. CanLoad: prevents lazy module download for unauthorized users (unlike CanActivate which loads the module then blocks). Resolve: fetches data before the route component initializes. Modern Angular uses functional guards (plain functions).
Q5:

What is the purpose of the Angular Router Outlet and how does routing technically work?

Mid

Answer

RouterOutlet is a dynamic placeholder where Angular loads components based on the active route.

Routing parses the URL, matches it with route configuration, runs guards/resolvers, and finally loads the mapped component into the outlet.

Quick Summary: RouterOutlet is a placeholder directive that Angular fills with the routed component. When navigation occurs, Router matches the URL to a route config, loads the component (lazy or eager), and renders it inside the nearest RouterOutlet. Nested routing: child routes render in a child RouterOutlet defined in the parent component's template. Multiple named outlets support complex layouts.
Q6:

What is Lazy Loading in Angular and why is it important?

Mid

Answer

Lazy loading loads feature modules only when required.

This reduces initial bundle size, speeds up first load, improves performance, and helps modularize large enterprise applications.

Quick Summary: Lazy loading splits the app into feature modules that load on demand. Configure: {path: "admin", loadChildren: () => import("./admin/admin.module").then(m => m.AdminModule)}. The admin bundle is only downloaded when user navigates to /admin. Reduces initial bundle size dramatically. Angular 14+ also supports standalone component lazy loading without modules.
Q7:

What is Preloading Strategy in Angular?

Mid

Answer

Preloading loads lazy-loaded modules in the background after the main app loads.

Benefits include faster navigation and balanced app performance.

Angular provides built-in strategies like PreloadAllModules and supports custom strategies.

Quick Summary: Preloading strategies load lazy modules in the background after the initial app loads, so navigation feels instant. PreloadAllModules: preloads all lazy modules after init. Custom strategy: implement PreloadingStrategy to selectively preload (e.g., preload based on user role or flag). QuicklinkStrategy preloads modules for routes visible in viewport. Balance between initial load and preload bandwidth usage.
Q8:

What is the role of ChangeDetectorRef and when should it be used?

Mid

Answer

ChangeDetectorRef gives manual control over Angular’s change detection.

Used when working with OnPush, avoiding heavy re-renders, handling updates outside Angular zones, or running performance-sensitive operations.

Quick Summary: ChangeDetectorRef gives manual control over change detection. detach() removes a component from the CD tree (must manually call detectChanges()). markForCheck() marks an OnPush component to be checked on next CD cycle (useful when data changes externally). detectChanges() synchronously runs CD on this component and its children. Use when integrating non-Angular code that changes state without triggering Zone.js.
Q9:

What are Angular Schematics and why are they used?

Mid

Answer

Schematics automate code generation, enforcing consistent structure across the project.

They generate modules, components, upgrade Angular versions, and apply organization-wide architecture rules.

Quick Summary: Angular Schematics are code generators used by Angular CLI (ng generate). They automate creating files with proper structure, updating NgModule declarations, and following project conventions. Write custom schematics to enforce team standards: auto-generate boilerplate, apply company conventions to new components, add required files (story files, test files) automatically.
Q10:

What is the difference between Shared Module and Core Module in Angular?

Mid

Answer

Shared Module contains reusable components, pipes, and directives and can be imported many times.

Core Module holds global singletons like services, interceptors, and layout components, imported only once.

This separation improves architecture, scalability, and avoids duplicate service instances.

Quick Summary: SharedModule contains components, directives, and pipes used across multiple feature modules. Export what you share, don't provide services (use root or feature-level providers). CoreModule contains app-wide singleton services (auth, logging) and is imported only in AppModule. Import SharedModule in feature modules. CoreModule should throw error if imported twice (to enforce singleton).
Q11:

What is the purpose of Angular zones?

Mid

Answer

Zones track asynchronous operations and automatically trigger change detection.
Without zones, Angular would not know when async tasks like timeouts or HTTP calls finish.
Quick Summary: Angular zones (Zone.js) intercept async operations to detect when the app needs change detection. Zones patch browser APIs like setTimeout, Promise, and event listeners. When any patched async operation completes, Angular knows to run change detection. This is why you don't need to manually trigger UI updates in Angular when data changes asynchronously.
Q12:

What are Angular lifecycle phases in change detection?

Mid

Answer

Angular runs two phases:
Check phase: Verifies bindings.
Update phase: Applies DOM updates and triggers child checks.
This ensures UI consistency.
Quick Summary: Angular CD lifecycle phases: 1) Mark view dirty (async event fires), 2) ApplicationRef.tick() starts CD from root, 3) For each component in tree: check host bindings, run ngDoCheck, check child components recursively, 4) Update DOM for changed components. OnPush skips the subtree unless input changed. ngAfterViewChecked fires after each CD cycle where a view is checked.
Q13:

Difference between template-driven and reactive forms?

Mid

Answer

Template-driven forms rely on template directives and implicit data flow.
Reactive forms use explicit FormControl objects, enabling predictable state, dynamic validation, and easier testing.
Quick Summary: Template-driven: uses directives (ngModel), form logic in template, async validation is complex, less testable, less code for simple cases. Reactive: FormGroup/FormControl in TypeScript, validators are plain functions, dynamic form fields with FormArray, unit-testable without the DOM. Reactive is preferred for any form with complex validation, conditional fields, or dynamic structure.
Q14:

How does Angular handle dependency resolution with multiple providers?

Mid

Answer

Angular uses hierarchical injectors.
If the same token exists in multiple injectors, the nearest injector to the component wins.
Quick Summary: Angular injector tree: when multiple providers for the same token exist at different levels (root, module, component), the injector closest to the consumer wins. The injector walks up the tree until it finds a provider. Use InjectionToken for non-class dependencies. forwardRef() resolves circular dependencies at decoration time. Multi providers (multi: true) merge multiple values for the same token into an array.
Q15:

What is the module-with-providers pattern?

Mid

Answer

Used when modules need root-level configuration.
Allows importing a module multiple times without re-registering global services.
Quick Summary: ModuleWithProviders pattern lets a module export providers that are only configured when imported with forRoot(). RouterModule.forRoot(routes) registers the router globally with routes. RouterModule.forChild(routes) doesn't re-provide the router service. Use this pattern for library modules that need to be configured once at root level but imported in multiple feature modules.
Q16:

Purpose of entryComponents in pre-Ivy Angular?

Mid

Answer

Before Ivy, Angular needed entryComponents to know which components could be created dynamically.
Ivy removed this requirement.
Quick Summary: In pre-Ivy Angular (ViewEngine), entryComponents listed components created dynamically (not via selector in templates) so the compiler would include them in the bundle. Components referenced only in template selectors were automatically included. Ivy made entryComponents obsolete - it uses a different compilation model that discovers all components. In Angular 9+, entryComponents is a no-op.
Q17:

How does Angular parse templates internally?

Mid

Answer

Angular converts templates into Ivy instructions that directly execute, improving performance and eliminating heavy compilation.
Quick Summary: Angular compiler parses template HTML into an AST (Abstract Syntax Tree). It analyzes bindings, directives, pipes, and structural directives. Ivy compiles each component into a set of template instructions (a render function). These instructions directly call Angular runtime APIs to create DOM nodes and set up bindings. This replaces the old ViewEngine approach of generating ngFactory files.
Q18:

How does Angular detach or skip change detection?

Mid

Answer

Using OnPush, ChangeDetectorRef.detach(), or manual checks, Angular can skip change detection for performance optimization.
Quick Summary: Detach from CD: ChangeDetectorRef.detach() removes the component from the CD tree - Angular won't check it automatically. Manually call detectChanges() when needed. Skip CD: OnPush strategy skips components unless inputs change. Run code outside zone: NgZone.runOutsideAngular() prevents zone notifications from triggering CD for non-UI work. These techniques are essential for performance-critical components.
Q19:

How does Angular sanitize DOM?

Mid

Answer

Angular uses DomSanitizer to remove harmful HTML, URLs, and scripts, protecting against XSS attacks.
Quick Summary: Angular sanitizes values bound to innerHTML, style, URL attributes, and resource URLs by default. The DomSanitizer strips dangerous HTML before inserting into DOM (prevents XSS). Property binding [innerHTML] is automatically sanitized. To bypass sanitization (with care): DomSanitizer.bypassSecurityTrust*(). Angular's template syntax safely escapes interpolated values - they're text nodes, not HTML.
Q20:

Difference between value providers and factory providers?

Mid

Answer

Value providers supply literal constants.
Factory providers generate values dynamically using logic or dependencies.
Quick Summary: Value provider: provide a static value for a token (useValue: myConfig). Factory provider: use a function to create the service (useFactory: () => new MyService(dep), deps: [Dep]) - enables conditional creation logic or passing constructor args. Class provider (useClass): use a different class than the token. Existing provider (useExisting): alias one token to another. Factories are for complex initialization logic.
Q21:

How does Angular perform content projection?

Mid

Answer

Angular uses ng-content slots and tracks projected nodes using host views, integrating child templates with parent DOM.
Quick Summary: Angular processes directives at compile time. The component template declares content projection slots with selectors. When Angular renders the component, it moves matching projected elements from the parent template into the slots. Multi-slot projection: for specific content. Projected content belongs to the parent component's view (not the child's).
Q22:

Role of ApplicationRef in Angular?

Mid

Answer

Manages the component tree, performs manual change detection, and supports custom bootstrapping.
Quick Summary: ApplicationRef represents the Angular application. tick() manually runs change detection for the whole app (useful when Zone.js is disabled). attachView() adds a HostView (from ComponentRef) to the app's change detection tree. isStable Observable emits when the app has no pending async work (used for server-side rendering to know when to serialize). Rarely used directly in app code.
Q23:

What happens when creating a component with ViewContainerRef?

Mid

Answer

Angular creates a host view, initializes metadata, sets bindings, and renders template instructions.
Quick Summary: ViewContainerRef.createComponent() dynamically creates a component and inserts it into the DOM at the view container's location. Returns a ComponentRef with the component instance and host view. The created component is added to the host module's CD tree. Destroy with ComponentRef.destroy(). Used for: dynamic dialogs, tooltips, dynamic form fields. More powerful than *ngIf for programmatic creation.
Q24:

Difference between embedded views and host views?

Mid

Answer

Host views belong to components.
Embedded views are created from ng-template or structural directives.
Quick Summary: Embedded view: created from a TemplateRef (ng-template) - renders a reusable template chunk into the DOM. Host view: the view of a dynamically created component (ComponentRef.hostView). Both are ViewRef instances and can be attached to a ViewContainerRef. Structural directives use embedded views: *ngIf creates/destroys an embedded view for the ng-template content.
Q25:

What is the Angular renderer?

Mid

Answer

Renderer abstracts DOM operations, enabling Angular to run in environments like SSR, Web Workers, or NativeScript.
Quick Summary: Angular Renderer2 provides a platform-agnostic API for DOM manipulation. Instead of direct DOM calls (document.createElement, element.style.color), use Renderer2 methods. This allows Angular to run in non-browser environments (SSR, Web Workers, NativeScript). Inject Renderer2 and use: createElement, appendChild, setStyle, setAttribute, addClass, listen. Prefer over direct DOM access for platform independence.
Q26:

How does Angular handle heavy asynchronous UI operations?

Mid

Answer

Uses zone.js, task queues, microtasks, and triggers change detection after async tasks complete.
Quick Summary: Handle heavy async UI operations: use trackBy in *ngFor to minimize DOM re-creation, virtual scrolling (cdk-virtual-scroll-viewport) for long lists, debounce user inputs before processing, run heavy computation in Web Workers (off main thread), use OnPush CD to minimize checks, paginate data instead of loading everything, and use requestAnimationFrame for animation-related work.
Q27:

Difference between template reference and template input variables?

Mid

Answer

Template reference variables refer to DOM or component instances.
Template input variables provide local directive context, such as ngFor.
Quick Summary: Template reference variable (#ref): references a DOM element or component instance in the template. lets you use nameInput.value. Template input variable (let-item): used inside structural directives to reference the current iteration value.
  • - item is a template input variable bound by the *ngFor directive's context.
  • Q28:

    How do Angular directives communicate?

    Mid

    Answer

    Communication via selectors, dependency injection, or parent-child directive references.
    Quick Summary: Directives communicate through: parent-child via DI (inject parent directive in child constructor - same element or ancestor), shared service (both directives inject the same service), host binding/listener (directive reads/modifies host element), or through the component's @Input/@Output if the directive is on a component. Siblings on the same element can reference each other via DI.
    Q29:

    What is PlatformBrowserModule?

    Mid

    Answer

    Provides browser-specific services and bootstrapping required to run Angular apps in a browser.
    Quick Summary: BrowserModule provides browser-specific implementations of Angular services (DOM renderer, browser platform), bootstraps the app, and exports CommonModule (NgIf, NgFor, async pipe etc.). Import BrowserModule only in AppModule (root). Feature modules import CommonModule (included in BrowserModule) instead. Importing BrowserModule in lazy-loaded feature modules throws an error.
    Q30:

    How does Angular handle structural directives internally?

    Mid

    Answer

    Transforms structural directives into template instructions manipulating embedded views.
    Quick Summary: Structural directives use embedded views internally. When you write *ngIf="show", Angular desugars it to: . The directive receives a TemplateRef and ViewContainerRef via DI. It calls viewContainerRef.createEmbeddedView(templateRef) to show and viewContainerRef.clear() to hide. The asterisk is pure syntactic sugar for the ng-template pattern.
    Q31:

    What are host bindings and host listeners?

    Mid

    Answer

    Host bindings bind properties on the host element.
    Host listeners listen to events on the host element.
    Quick Summary: Host bindings and listeners let directives/components interact with their host element. @HostBinding("class.active") isActive: boolean adds class "active" to the host element when isActive is true. @HostListener("click", ["$event"]) onClick(event) handles click events on the host element. Both are Angular's clean alternative to direct DOM manipulation in directives.
    Q32:

    Difference between RouterModule.forRoot and forChild?

    Mid

    Answer

    forRoot creates the global router services.
    forChild adds child routes without recreating router instances.
    Quick Summary: RouterModule.forRoot() registers the Router service and root routes - call once in AppModule. RouterModule.forChild() registers additional routes for a lazy feature module without re-providing the Router service. Calling forRoot() in a lazy module would create a second Router instance and break routing. Feature modules always use forChild().
    Q33:

    How does Angular router reuse strategy work?

    Mid

    Answer

    Determines whether route components should be cached or recreated during navigation.
    Quick Summary: RouteReuseStrategy determines when Angular destroys and recreates components on navigation. Default: component is destroyed when you navigate away and recreated on return. Custom strategy: implement RouteReuseStrategy to cache component state across navigation (useful for list pages where you want scroll position preserved). Angular CDK or custom implementations store/restore detached view trees.
    Q34:

    What is navigation extras?

    Mid

    Answer

    Additional navigation configuration like query params, fragments, state, or skipLocationChange.
    Quick Summary: NavigationExtras are options passed to router.navigate() or router.navigateByUrl(). Options include: queryParams (add URL query parameters), fragment (scroll to anchor), replaceUrl (replace history entry instead of push), skipLocationChange (navigate without updating URL), relativeTo (navigate relative to a route). Example: router.navigate(["/users"], {queryParams: {page: 2}}).
    Q35:

    How does Angular handle slow-loading modules?

    Mid

    Answer

    Uses lazy loading and route splitting so modules load only when needed.
    Quick Summary: Angular handles slow-loading lazy modules with loading indicators via Router events. Listen for NavigationStart (show spinner) and NavigationEnd/NavigationError (hide spinner). Preloading strategies reduce perceived load time by downloading modules in background after initial load. Add a loading component to router config as a placeholder while lazy bundles download.
    Q36:

    How does Angular's animation engine work?

    Mid

    Answer

    Converts animation metadata into CSS or WebAnimation instructions and manages start/cancel/done events.
    Quick Summary: Angular Animations uses the Web Animations API and CSS transitions via @angular/animations. Define state transitions in @Component animations metadata with trigger(), state(), transition(), and animate(). The animation engine applies CSS changes with optimal timing. AnimationBuilder allows programmatic control. Angular animations support sequence(), group(), stagger() for complex choreographed animations.
    Q37:

    Limitations of ChangeDetectionStrategy.OnPush?

    Mid

    Answer

    Requires immutability and manual notifications; otherwise UI may not update automatically.
    Quick Summary: OnPush limitations: if you mutate an object/array in place (push to array, modify nested property), OnPush won't detect the change because the reference is the same. You must create new references (immutable updates). Also, changes from outside Angular's zone (third-party callbacks) won't trigger CD automatically - call markForCheck() or detectChanges() manually. Signals (Angular 17+) solve these limitations.
    Q38:

    Difference between host elements and component elements?

    Mid

    Answer

    Host element is where the component attaches.
    Component elements are internal template nodes.
    Quick Summary: Host element is the DOM element matching a component's or directive's selector. Component element refers to the element the component is applied to. For , the div tag in the parent template is the host element. The component's template content is rendered inside the host element. Host bindings modify the host element itself. Shadow DOM encapsulates styles within the host element boundary.
    Q39:

    How does Angular handle global error handling?

    Mid

    Answer

    Uses ErrorHandler to centralize uncaught errors.
    Custom handlers can log errors or show user-friendly messages.
    Quick Summary: Global error handling in Angular: implement ErrorHandler interface and provide it in AppModule. The handleError() method is called for all uncaught errors. Use it to: log errors to a monitoring service (Sentry, Datadog), show a user-friendly error UI, and handle specific error types differently. HTTP errors should be handled in interceptors or catchError operators, not in the global handler.

    Curated Sets for Angular

    No curated sets yet. Group questions into collections from the admin panel to feature them here.

    Ready to level up? Start Practice