Questions III Flashcards

1
Q

What is lazy loading?

A

Lazy loading is one of the most useful concepts of Angular Routing. It helps us to download the web pages in chunks instead of downloading everything in a big bundle. It is used for lazy loading by asynchronously loading the feature module for routing whenever required using the property loadChildren.

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

How to use polyfills in Angular application?

A

The Angular CLI provides support for polyfills officially.

A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.

When you create a new project with the ng new command, a src/polyfills.ts configuration file is created as part of your project folder. This file includes the mandatory and many of the optional polyfills as JavaScript import statements. Let’s categorize the polyfills,

Mandatory polyfills: These are installed automatically when you create your project with ng new command and the respective import statements enabled in ‘src/polyfills.ts’ file.

Optional polyfills: You need to install its npm package and then create import statement in ‘src/polyfills.ts’ file. For example, first you need to install below npm package for adding web animations (optional) polyfill. bash npm install –save web-animations-js and create import statement in polyfill file. javascript import ‘web-animations-js’;

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

What is AOT compiler?

A

The AOT compiler is part of a build process that produces a small, fast, ready-to-run application package, typically for production. It converts your Angular HTML and TypeScript code into efficient JavaScript code during the build phase before the browser downloads and runs that code.

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

What are reactive forms?

A

Reactive forms is a model-driven approach for creating forms in a reactive style (form inputs changes over time). These are built around observable streams where form inputs and values are provided as streams of input values.

Let’s follow the below steps to create reactive forms,

Register the reactive forms module which declares reactive-form directives in your app

Create a new FormControl instance and save it in the component
userName = new FormControl(‘’);

Register the FormControl in the template:
<input type=”text” [formControl]=”userName”>

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

What are dynamic forms?

A

Dynamic forms is a pattern in which we build a form dynamically based on metadata that describes a business object model. You can create them based on reactive form API.

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

What are template driven forms?

A

Template driven forms are model-driven forms where you write the logic, validations, controls etc, in the template part of the code using directives.

They are suitable for simple scenarios and uses two-way binding with [(ngModel)] syntax. For example, you can create register form easily by following the below simple steps,

Bind the form from template to the component using ngModel syntax
<input type=”text” class=”form-control” id=”name”
required
[(ngModel)]=”model.name” name=”name”>

Attach NgForm directive to the tag in order to create FormControl instances and register them:
<form #registerForm=”ngForm”>

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

What are the different ways to group form controls?

A

Reactive forms provide two ways of grouping multiple related controls.

FormGroup: It defines a form with a fixed set of controls those can be managed together in an one object. It has same properties and methods similar to a FormControl instance. This FormGroup can be nested to create complex forms as below.

FormArray: It defines a dynamic form in an array format, where you can add and remove controls at run time. This is useful for dynamic forms when you don’t know how many controls will be present within the group.

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

What are the types of validator functions?

A

In reactive forms, the validators can be either synchronous or asynchronous functions,

Sync validators: These are the synchronous functions which take a control instance and immediately return either a set of validation errors or null. Also, these functions passed as second argument while instantiating the form control. The main use cases are simple checks like whether a field is empty, whether it exceeds a maximum length etc.

Async validators: These are the asynchronous functions which take a control instance and return a Promise or Observable that later emits a set of validation errors or null. Also, these functions passed as second argument while instantiating the form control. The main

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

Can you give an example of built-in validators?

A

In reactive forms, you can use built-in validator like required and minlength on your input form controls. For example, the registration form can have these validators on name input field

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

What is host property in css?

A

The :host pseudo-class selector is used to target styles in the element that hosts the component. Since the host element is in a parent component’s template, you can’t reach the host element from inside the component by other means. For example, you can create a border for parent element as below,

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

What is Component Test Harnesses?

A

A component harness is a testing API around an Angular directive or component to make tests simpler by hiding implementation details from test suites. This can be shared between unit tests, integration tests, and end-to-end tests. The idea for component harnesses comes from the PageObject pattern commonly used for integration testing.

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

What is content projection?

A

Content projection is a pattern in which you insert, or project, the content you want to use inside another component.

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

What is ng-content and its purpose?

A

The ng-content is used to insert the content dynamically inside the component that helps to increase component reusability.

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

What is standalone component?

A

A standalone component is a type of component which is not part of any Angular module. It provides a simplified way to build Angular applications.

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

What is hydration?

A

Hydration is the process that restores the server side rendered application on the client.

This includes things like reusing the server rendered DOM structures, persisting the application state, transferring application data that was retrieved already by the server, and other processes.

To enable hydration, we have to enable server side rendering or Angular Universal. Once enabled, we can add the following piece of code in the root component.

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

What are Angular Signals?

A

A signal is a wrapper around a value that can notify interested consumers when that value changes. Signals can contain any value, from simple primitives to complex data structures.

17
Q
A