Angular Interview Flashcards

These questions cover the fundamental concepts and technical aspects typically asked during Angular interviews.

1
Q

What is Angular?

A

Angular is a platform and framework for building single-page client applications using HTML and TypeScript. It provides a set of tools and libraries for routing, forms, HTTP client communication, and more, making it an all-in-one solution for building robust web applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the concept of components in Angular

A

Components are the building blocks of an Angular application. A component is a TypeScript class with a decorator that defines a view (HTML template), style (CSS or SCSS), and business logic. Every Angular application has at least one root component, and components can be nested within each other to create a tree-like structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between Angular and AngularJS?

A

Architecture: Angular uses a component-based architecture, while AngularJS is MVC-based.

Language: Angular uses TypeScript, while AngularJS is based on JavaScript.

Performance: Angular has better performance due to features like AOT (Ahead-of-Time) compilation and a better change detection mechanism.

Mobile Support: Angular is designed with mobile support in mind, whereas AngularJS is not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are services in Angular?

A

Services are used to create reusable business logic that can be shared across multiple components. They are typically used for data retrieval, handling HTTP requests, or performing calculations. Services are injected into components using Angular’s dependency injection (DI) system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is dependency injection (DI) in Angular?

A

Dependency Injection is a design pattern in which a class asks for dependencies from external sources rather than creating them itself. Angular’s DI framework allows developers to define and inject dependencies like services into components, making the code modular and easier to test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Angular CLI, and what are some of its main commands?

A

Angular CLI (Command Line Interface) is a tool that helps automate the development workflow in Angular projects. It offers commands like:

  • ng new: Create a new Angular project.
  • ng serve: Run the application in development mode.
  • ng generate component <component-name>: Generate a new component.</component-name>
  • ng build: Build the application for deployment.
  • ng test: Run unit tests for the project.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is change detection in Angular?

A

Change detection is a mechanism by which Angular determines what changes have occurred in the data and updates the view accordingly. Angular uses zones and a change detection strategy to optimize rendering by only updating the affected parts of the DOM.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain the lifecycle hooks in Angular.

A

Angular components have a series of lifecycle hooks that provide visibility into the different stages of a component’s lifecycle:

  • ngOnChanges: Called when an input-bound property changes.
  • ngOnInit: Called once the component is initialized.
  • ngDoCheck: Called during every change detection run.
  • ngAfterContentInit: Called after content (ng-content) has been projected.
  • ngAfterContentChecked: Called after every check of the projected content.
  • ngAfterViewInit: Called after the component’s view has been fully initialized.
  • ngAfterViewChecked: Called after every check of the component’s view.
  • ngOnDestroy: Called just before the component is destroyed.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Angular’s Ahead-of-Time (AOT) Compilation?

A

AOT compilation is a process in which the Angular compiler converts Angular HTML and TypeScript code into efficient JavaScript code before the browser downloads and runs the application. This leads to faster rendering, fewer asynchronous requests, and better security.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Angular modules?

A

Modules in Angular are containers that group components, directives, pipes, and services, making them cohesive blocks of functionality. Each Angular application has at least one module, the root module, which bootstraps the application. Other feature modules can be created to encapsulate functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are observables, and how are they used in Angular?

A

Observables are used for handling asynchronous data streams and events in Angular. The HttpClient service, for example, returns observables when making HTTP requests. Observables can be subscribed to and used with operators such as map, filter, and mergeMap from the RxJS library to transform or combine data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How would you handle forms in Angular?

A

Angular provides two approaches to handling forms:

  • Template-driven forms: Suitable for simple forms, managed using Angular directives such as ngModel.
  • Reactive forms: Suitable for complex forms, managed programmatically using FormGroup, FormControl, and FormBuilder.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is lazy loading in Angular?

A

Lazy loading is a technique in which modules are loaded on demand rather than all at once. It reduces the initial load time of an application by only loading the required modules for a particular route. This is achieved using Angular’s router configuration.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Angular Material?

A

Angular Material is a UI component library that follows Google’s Material Design principles. It provides pre-built, customisable components like buttons, cards, dialogs, and tables to enhance the UI and UX of Angular applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a router in Angular?

A

Angular’s router is a tool that enables navigation between different views or pages of an application. It provides route configurations, route guards, and parameterised routes, making it easy to manage navigation and route changes in a single-page application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the different types of data binding in Angular, and how do they work?

A

In Angular, data binding refers to the communication mechanism between the component’s class (TypeScript/logic) and its template (HTML/view). There are four main types of data binding in Angular:

  1. Interpolation: Displays data from the component to the view.
  2. Property Binding: Binds a property from the component to an HTML element property.
  3. Event Binding: Sends user actions from the view to the component.
  4. Two-way Binding: Syncs data between the view and the component in both directions.
17
Q

What are the use cases for each type of binding?

A
  • Use interpolation when you want to display values in the view.
  • Use property binding when you need to bind values to element attributes, like setting src for an image or disabled for a button.
  • Use event binding when you want to react to user interactions, such as clicks or typing.
  • Use two-way binding for form inputs or components that need to be synchronised with data in the component class.
18
Q

Why does Angular use one-way binding instead of two-way binding everywhere?

A

Angular primarily uses one-way data binding because it’s more efficient and predictable. Two-way data binding is often overkill and can introduce complexity. Therefore, it’s recommended to use two-way binding only when necessary (e.g., with form inputs).

19
Q

How does Angular handle DOM manipulation in Structural Directives?

A

Angular removes and recreates DOM elements efficiently by keeping track of template references and conditions, making sure the DOM only contains the necessary elements.

20
Q
A