Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

Angular Interview Questions

The document provides a comprehensive overview of Angular, an open-source framework for building single-page applications using TypeScript. It covers key concepts such as components, data binding, directives, services, routing, and lifecycle hooks, along with their definitions and functionalities. Additionally, it discusses the differences between AOT and JIT compilation, the use of Promises and Observables, and the role of RxJS in Angular applications.

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Angular Interview Questions

The document provides a comprehensive overview of Angular, an open-source framework for building single-page applications using TypeScript. It covers key concepts such as components, data binding, directives, services, routing, and lifecycle hooks, along with their definitions and functionalities. Additionally, it discusses the differences between AOT and JIT compilation, the use of Promises and Observables, and the role of RxJS in Angular applications.

Uploaded by

Ashok Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Angular Interview Questions & Answers

1. What is Angular and its main principles?

Angular is an open-source, TypeScript-based framework developed by Google for


building single-page applications (SPAs). It provides a structured approach to web
development.

Main Principles of Angular:

 Component-based architecture
 Data binding
 Dependency Injection (DI)
 Directives
 Routing
 Services and Observables
 Modular structure

2. What is TypeScript in Angular?

TypeScript is a statically typed superset of JavaScript that enhances JavaScript’s


capabilities, making it easier to maintain large-scale applications. It is the preferred
language for Angular development.

3. What is a Component in Angular?

A component is a fundamental building block of an Angular application. It consists of:

 Class (TypeScript file) – Defines business logic


 Template (HTML file) – Defines the view
 Styles (CSS or SCSS file) – Defines the component-specific styles
 @Component decorator – Provides metadata for Angular

4. What are Single Page Applications (SPAs) and their key characteristics?

A Single Page Application (SPA) dynamically updates the view without reloading the
entire page.

Key Characteristics:

 Dynamic Content Loading


 Smooth User Experience
 Client-Side Routing
 Rich User Interfaces
 Data Binding
 Asynchronous Data Handling

5. What is Data Binding? Explain its types.


Data binding establishes communication between the model (data) and the view (UI).

Types of Data Binding:

 Interpolation (One-Way Binding): {{ expression }}


 Property Binding (One-Way Binding): [property]="expression"
 Event Binding (One-Way Binding): (event)="expression"
 Two-Way Binding: [(ngModel)]="expression"

6. What are Decorators in Angular?

Decorators provide metadata and modify the behavior of Angular components, services,
and directives.

Common Decorators:

 @NgModule – Defines an Angular module


 @Component – Defines an Angular component
 @Directive – Creates custom directives
 @Injectable – Defines a service for DI
 @Input – Passes data from parent to child component
 @Output – Sends data from child to parent component

7. What are Directives in Angular and their types?

Directives modify the behavior of HTML elements.

Types of Directives:

 Component Directives – Components with a template


 Structural Directives – Modify the DOM structure (*ngIf, *ngFor)
 Attribute Directives – Modify element appearance (ngClass, ngStyle)

8. What are Pipes in Angular?

Pipes are used to transform data in templates.

Built-in Pipes:

 DatePipe – Formats dates


 UpperCasePipe, LowerCasePipe – Changes text case
 CurrencyPipe, DecimalPipe, PercentPipe – Formats numbers

9. What is String Interpolation in Angular?

String interpolation allows embedding expressions inside HTML templates using {{ }}


syntax.

10. What are Pure and Impure Pipes?


 Pure Pipes – Returns the same output for the same input (default behavior).
 Impure Pipes – Can produce different outputs for the same input due to
external factors.

11. Explain Lifecycle Hooks in Angular.

Lifecycle hooks allow developers to execute logic at different phases of a component's


lifecycle.

Common Lifecycle Hooks:

 ngOnChanges() – Executes when input properties change


 ngOnInit() – Executes after component initialization
 ngDoCheck() – Executes during every change detection cycle
 ngAfterContentInit() – Executes after content is projected
 ngAfterViewInit() – Executes after view initialization
 ngOnDestroy() – Executes before component destruction

12. How do components communicate in Angular?

Methods for Data Sharing:

 @Input() – Parent to child component


 @Output() with EventEmitter – Child to parent component
 Service-based Communication – Shared service for data transfer

13. What are Event Emitters in Angular?

EventEmitter allows components to emit custom events that parent components can
listen to.

14. What is View Encapsulation in Angular?

View encapsulation ensures that styles defined for one component do not affect others.

15. What is Routing in Angular?

Routing enables navigation between different views in an SPA.

Key Routing Features:

 RouterModule – Configures routing


 RouterOutlet – Defines where components are rendered
 RouterLink – Provides navigation links
 Route Guards – Secures routes

16. What are Templates in Angular?


A template defines the structure of a component’s view using HTML and Angular-
specific syntax.

17. What is an Angular Module?

A module organizes components, directives, and services into cohesive units. The root
module is AppModule.

18. What is the @NgModule decorator?

The @NgModule decorator configures an Angular module by defining components,


directives, pipes, and providers.

19. Advantages of AOT Compilation

 Faster initial load time


 Smaller bundle size
 Improved security
 Early error detection

20. Difference Between AOT and JIT

Feature AOT (Ahead-of-Time) JIT (Just-in-Time)


Compilation Time Before runtime At runtime
Performance Faster Slower
Use Case Production Development

21. What are Promises and Observables?

 Promises – Handles a single asynchronous event.


 Observables – Handles multiple asynchronous events over time (RxJS).

22. What is FormsModule in Angular?

The FormsModule enables two-way data binding for template-driven forms.

23. What is ReactiveFormsModule in Angular?

The ReactiveFormsModule allows building reactive forms using FormControl,


FormGroup, and FormArray.

24. What is the PipeTransform Interface?

The PipeTransform interface is used to create custom pipes by implementing the


transform method.

25. What are Services in Angular?


A service is an injectable class that provides reusable logic across components. Created
using:

ng generate service my-service-name

26. What is ngOnInit?

ngOnInit() is a lifecycle hook that runs after component initialization.

27. What is Eager and Lazy Loading?

 Eager Loading – Loads all modules upfront.


 Lazy Loading – Loads modules on demand, improving performance.

28. How does an Angular Application Work?

1. Bootstrapping – main.ts initializes AppModule.


2. Modules – Organize the application.
3. Components – Define the UI.
4. Templates & Binding – Manage views.
5. Services & DI – Handle business logic.
6. Routing – Controls navigation.
7. Change Detection – Updates the DOM.

29. What is MVVM Architecture?

MVVM (Model-View-ViewModel) separates logic from the UI, improving maintainability.

30. What is RxJS in Angular?

RxJS is a library for reactive programming using Observables.

31. What are Router Links?

RouterLink allows navigation between different views without reloading the page.

32. What are HTTP Interceptors?

HTTP interceptors modify requests and responses globally, commonly used for
authentication and logging.

You might also like