Some important question answers for Angular interview - Part 1

What are libraries in Angular?

An Angular library is an Angular project that differs from an application in that it cannot run on its own. A library must be imported and used in an application. Libraries extend Angular's base features. 

Why we use export in Angular?

An export what you put is the exports property of the @NgModule decorator. It enables an Angular module to expose some of its components/directives/pipes to the other modules in the applications. Without it, the components/directives/pipes defined in a module could only be used in that module.

How to use dependency injection in Angular?

The first step is to add the @Injectable decorator to show that the class can be injected. The next step is to make it available in the DI by providing it. A dependency can be provided in multiple places: At the Component level, using the providers field of the @Component decorator.

What is the difference between a service and a component in Angular?

What is the difference between Angular service and component? An Angular component is responsible for the application's user interface and behavior, including displaying data and handling user input. In contrast, an Angular service is a class that shares data and functionality across different components.

What is tree shaking in Angular?

Tree shaking refers to dead code elimination. It means that unused modules will not be included in the bundle during the build process. When we import and export modules in JavaScript, most of the time there is unused code floating around. Excluding that unused code (also referred as dead code) is called tree shaking.

What is change detection in Angular?

The change detectors provide a way to keep track of the component's previous and current states as well as its structure in order to report changes to Angular. If Angular gets the report from a change detector, it instructs the corresponding component to re-render and update the DOM accordingly.

What are templates in Angular?

A template is a form of HTML that tells Angular how to render the component. Views are typically organized hierarchically, allowing you to modify or show and hide entire UI sections or pages as a unit. The template immediately associated with a component defines that component's host view.

What is the shadow root in Angular?

The root node of a Document Object Model subtree that is rendered separately from a document's main Document Object Model tree is the ShadowRoot interface of the Shadow DOM API. If an element was generated using Element, its Element. shadowRoot property could be used to retrieve a reference to its shadow root.

What is host ng deep?

The ::ng-deep pseudo-class selector

If we want our component styles to cascade to all child elements of a component, but not to any other element on the page, we can currently do so using by combining the :host with the ::ng-deep selector: :host ::ng-deep h2 { color: red; }

What is observable in Angular?

An Observable is a data stream that can emit multiple values over time, and subscribers can listen to these emitted values. This pattern is ideal for scenarios like HTTP requests, event handling, or dealing with real-time data, where you need to respond to data as it arrives or changes.

What are promises in Angular?

A promise in angular is a JavaScript object which produces a value after an async operation is executed successfully. If the operation does not execute successfully, then it generates an error. A promise in angular is a class-based object, it is created using the new keyword and its constructor function.

What is forkJoin?

It allows you to combine the results of multiple HTTP requests. After some tinkering, I came to the conclusion that forkJoin was the right tool for the job. forkJoin is an RxJS operator that allows you to wait for multiple Observables to complete and then emits their latest value as an array.

 How to call multiple APIs in Angular?

This can be achieved by using forkJoin, this operator takes an array of observables and waits for all the source observables to complete. Once they all complete, it emits an array of the last emitted values from each observable.

What if one API fails in Fork-Join?

If any given observable errors at some point, forkJoin will error as well and immediately unsubscribe from the other observables.

What is mergeMap in Angular?

mergeMap operator is basically a combination of two operators – merge and map. The map part lets you map a value from a source observable to an observable stream. Those streams are often referred to as inner streams.

What is SwitchMap in Angular?

The Angular SwitchMap maps each value from the source observable into an inner observable, subscribes to it, and then starts emitting the values from it. It creates a new inner observable for every value it receives from the Source.

What is takeUntil in Angular?

takeUntil is mostly used to avoid memory leaks and clear resources once a certain even happens. In a component based application, takeUntil can be triggered by the event of a component destruction through a notifier observable. This notifier observable is commonly implemented as a Subject.

Is Angular synchronous or asynchronous?

A common misconception in Angular development is regarding whether observables are synchronous or asynchronous. A lot of (even experienced Angular developers) think that observables are async, but the truth is that they can be… Both synchronous and asynchronous.

What are subjects in Angular?

What Are Subjects in Angular? A Subject in RxJS is a special type of Observable that acts as both an observer and an observable. Think of it as a bridge that can both emit values (like a broadcaster) and subscribe to receive values (like a listener).

What is the use of defer in Angular?

This is the primary block that defines the section of content that is lazily loaded. It is not rendered initially– deferred content loads and renders once the specified trigger occurs or the when condition is met. By default, a @defer block is triggered when the browser state becomes idle.

What is the use of cloneDeep in Angular?

cloneDeep() method is handy for making a complete copy of a value. It goes deep into the value, copying everything inside it too.

Is RxJS synchronous or asynchronous?

RxJS is a library for building synchronous/asynchronous applications with observable sequences.

Is Angular is synchronous or asynchronous?

Angular is a popular JavaScript framework used for building web and mobile applications. One of the key features of Angular is its ability to handle both synchronous and asynchronous programming.

=================>

What is the difference between hot observable vs cold observable??

The main difference between hot and cold observables is when they start emitting values:

  • Cold observables
    Start emitting values when a subscription begins. Each subscriber receives the same sequence of events. 
  • Hot observables
    Always emit values, even if there are no subscribers. They are always being updated with new values.

A real-life example of a cold observable is watching a movie on Netflix. You can watch the movie anytime, and you will begin watching it from the beginning. A real-life example of a hot observable is watching a movie in theaters at a showtime. If you don't show up at the showtime, you will miss part of the movie.

=================>





Comments

Popular posts from this blog

PrimeNG tutorial with examples using frequently used classes

Docker and Kubernetes Tutorials and QnA

Building strong foundational knowledge in frontend development topics