Back to IQs
Angular Interview Questions
What is Angular?
Angular is a TypeScript-based open-source framework developed by Google for building web applications.
What are Angular components?
Components in Angular are the building blocks of an Angular application, consisting of a TypeScript class, an HTML template, and optional CSS styles.
What is data binding in Angular?
Data binding in Angular is the synchronization between the model and the view, including two-way binding, event binding, and property binding.
What is Angular CLI?
Angular CLI (Command Line Interface) is a powerful tool for automating various tasks in Angular development, including project creation, testing, and building.
What are directives in Angular?
Directives are special markers in the DOM that tell Angular to do something to an element, such as `ngIf`, `ngFor`, and custom directives.
What is Angular's dependency injection?
Dependency injection is a design pattern in Angular where dependencies are provided to a class instead of the class creating them, promoting modular and testable code.
What is Angular's module system?
In Angular, a module is a container for components, services, and other parts of an application. It helps organize the application structure.
What is RxJS in Angular?
RxJS is a library for reactive programming using Observables, making it easier to manage asynchronous data streams in Angular applications.
What is a service in Angular?
Services are reusable business logic providers in Angular applications that allow communication between components and other parts of the app.
What is Angular routing?
Angular routing enables navigation between different views or components in a single-page application without reloading the page.
What is the difference between ngOnInit and constructor in Angular?
The constructor is called first, and it is used for dependency injection. ngOnInit is called after the constructor and is used for component initialization.
What are pipes in Angular?
Pipes in Angular are used to transform data in templates, such as formatting dates or currency values, and are implemented as classes.
What is lazy loading in Angular?
Lazy loading is a technique in Angular where modules are loaded only when needed, improving the initial load time of the application.
What is Angular's change detection mechanism?
Angular's change detection mechanism keeps track of changes in data models and automatically updates the view when the model changes.
What is an observable in Angular?
An Observable is a stream of data that can be observed and subscribed to. It is a core concept in Angular for handling asynchronous operations.
What is an interceptor in Angular?
An interceptor is a service that can modify HTTP requests or responses globally before they are sent or after they are received.
What is the difference between component and directive in Angular?
A component is a directive with a template, while a directive is a behavior or action that can be applied to an element without a template.
What is a form in Angular?
Forms in Angular can be used for collecting user input. Angular provides two types of forms: Template-driven forms and Reactive forms.
What is the purpose of NgModule in Angular?
NgModule is used to organize related code into cohesive blocks, including components, services, and other Angular features, and it defines an application or a feature module.
What is Angular's zone.js?
Zone.js is a library that helps Angular detect changes and update the view by tracking asynchronous operations and managing execution contexts.
What is Angular's ngModel?
ngModel is a directive used to bind the value of input elements in forms to component properties in Angular, enabling two-way data binding.
What are standalone components in Angular?
Standalone components declare their own imports and do not need to belong to an NgModule. They simplify application composition and support more direct lazy loading, while NgModules remain supported for existing applications.
What are Angular signals?
Signals are reactive state primitives that track reads and notify dependent consumers when values change. They can make local state updates more explicit; RxJS remains useful for asynchronous streams and event composition.
What is the difference between Default and OnPush change detection?
Default change detection checks broadly after asynchronous activity. OnPush checks when an input reference changes, an event occurs in the component, or reactive state notifies it, so immutable inputs and explicit state updates are important for correctness and performance.
When would you use switchMap, mergeMap, concatMap, or exhaustMap?
switchMap cancels the previous inner stream and is useful for typeahead searches. mergeMap runs work concurrently, concatMap queues work in order, and exhaustMap ignores new work while one is active, such as preventing duplicate form submissions.
How do you protect an Angular application from XSS and CSRF?
Avoid bypassing Angular sanitization and never render untrusted HTML without a reviewed sanitizer. Use server-side authorization, secure cookies with appropriate SameSite settings, CSRF protection for cookie-authenticated requests, and a Content Security Policy; client-side guards are not a security boundary.
What should you consider when enabling Angular SSR and hydration?
SSR renders initial HTML on the server, while hydration attaches Angular behavior in the browser without unnecessarily recreating the DOM. Keep server and browser output deterministic, isolate browser-only APIs, handle transfer state to avoid duplicate requests, and measure the effect on first paint and interaction readiness.
What is zoneless Angular change detection?
Zoneless Angular avoids relying on Zone.js to discover every asynchronous task and instead uses explicit reactive notifications and framework events. It can reduce unnecessary checks, but components must update state through supported signals, inputs, or other notification paths rather than mutating data silently.
How do you test an Angular component effectively?
Test observable behavior through the public template and inputs rather than private implementation details. Cover rendering, user interaction, loading and error states, accessibility semantics, and service boundaries; use focused component tests plus a smaller number of integration or end-to-end tests for routing and critical workflows.