Skip to main content
InterviewHubPRO
HomeTracksSection 2: Angular Master (283 Qs)
Section 2 of 64283 Questions (1 Per Page)

Angular Enterprise Architecture, Signals & Performance Master Interview Bank

Core Angular architecture, zoneless change detection, Signals reactivity, deferrable views (@defer), standalone components, control flow, RxJS interop, and microfrontends.

Curriculum Roadmap & Learning Path

10 Stages
Tip: Click any stage card above to instantly filter the question bank to that topic.10 Connected Milestones
283 of 283 Qs

Part 1: Architecture, Components, Directives & Lifecycle (1 - 35)

35 Questions
1
SeniorCode#Directives#Components

What is Angular Framework?

Angular is a TypeScript-based open-source front-end platform that makes it easy to build web, mobile and desktop applications. The major features of this framework include declarative templates, dependency injection, end to end tooling which ease application development.

2
SeniorCode#Directives#Components

What is the difference between AngularJS and Angular?

AngularJS (version 1.x) is a JavaScript framework, whereas Angular (version 2+) is a complete rewrite of AngularJS using TypeScript, providing better performance, mobile support, modularity, and a more modern architecture.

3
SeniorCode#Directives#Components

What is TypeScript?

TypeScript is a strongly typed superset of JavaScript created by Microsoft that adds optional types, classes, async/await and many other features, and compiles to plain JavaScript. Angular is written entirely in TypeScript as a primary language.

4
SeniorCode#Directives#Components

Write a pictorial diagram of Angular architecture?

The main building blocks of an Angular application are shown in the diagram below:.

5
SeniorCode#Directives#Components

What are the key components of Angular?

Component: These are the basic building blocks of an Angular application to control HTML views • Modules: An Angular module is a set of angular basic building blocks like components, directives, services etc. An application is divided into • Templates: These represent the views of an Angular application.

6
SeniorCode#Directives#Components

What are directives?

Directives add behaviour to an existing DOM element or an existing component instance.

7
SeniorCode#Directives#Components

What are components?

Components are the most basic UI building block of an Angular app, which form a tree of Angular components. These components are a subset of directives. Unlike directives, components always have a template, and only one component can be instantiated per element in a template. Let's see a simple example of Angular component.

8
SeniorCode#Directives#Components

What are the differences between Component and Directive?

In a short note, A component(@component) is a directive-with-a-template.

9
SeniorCode#Directives#Components

What is a template?

A template is a HTML view where you can display data by binding controls to properties of an Angular component. You can store your component's template in one of two places.

10
SeniorCode#Directives#Components

What is a module?

Modules are logical boundaries in your application and the application is divided into separate modules to separate the functionality of your application.

11
SeniorCode#Directives#Components

What are lifecycle hooks available?

Angular application goes through an entire set of processes or has a lifecycle right from its initiation to the end of the application. The representation of lifecycle in pictorial representation as follows.

12
SeniorCode#Directives#Components

What is a data binding?

Data binding is a core concept in Angular and allows to define communication between a component and the DOM, making it very easy to define interactive applications without worrying about pushing and pulling data. There are four forms of data binding(divided as 3 categories) which differ in the way the data is flowing.

13
SeniorCode#Directives#Components

What is metadata?

Metadata is used to decorate a class so that it can configure the expected behavior of the class. The metadata is represented by decorators.

14
SeniorCode#Directives#CLI

What is angular CLI?

Angular CLI(Command Line Interface) is a command line interface to scaffold and build angular apps using nodejs style (commonJs) modules. You need to install using below npm command, Below are the list of few commands, which will come handy while creating angular projects.

15
SeniorCode#Directives#Components

What is the difference between constructor and ngOnInit?

The Constructor is a default method of the class that is executed when the class is instantiated and ensures proper initialisation of fields in the class and its subclasses.

16
SeniorCode#Directives#Components

What is a service?

A service is used when a common functionality needs to be provided to various modules. Services allow for greater separation of concerns for your application and better modularity by allowing you to extract common functionality out of components.

17
Most AskedSeniorCode#Directives#Dependency Injection

What is dependency injection in Angular?

Dependency injection (DI), is an important application design pattern in which a class asks for dependencies from external sources rather than creating them itself.

18
SeniorCode#Directives#Components

How is Dependency Hierarchy formed?

Injectors in Angular have rules that can be leveraged to achieve the desired visibility of injectables in your applications. By understanding these rules, you can determine in which NgModule, Component, or Directive you should declare a provider.

19
SeniorCode#Directives#Components

What is the purpose of async pipe?

The AsyncPipe subscribes to an observable or promise and returns the latest value it has emitted. When a new value is emitted, the pipe marks the component to be checked for changes.

20
SeniorCode#Directives#Components

What is the option to choose between inline and external template file?

You can store your component's template in one of two places. You can define it inline using the template property, or you can define the template in a separate HTML file and link to it in the component metadata using the @Component decorator's templateUrl property.

21
SeniorCode#Directives#Components

What is the purpose of *ngFor directive?

Angular templates provide iterative rendering to display collections of items. You can render collections using either the Classic Built-in Structural Directive (ngFor) or the modern Built-in Control Flow (@for)** introduced in Angular 17+.

22
SeniorCode#Directives#Components

What is the purpose of *ngIf directive?

Angular provides conditional rendering to show or hide portions of the DOM based on a truthy/falsy condition. You can implement conditional rendering using the Classic Built-in Structural Directive (ngIf) or the modern Built-in Control Flow (@if)** introduced in Angular 17+.

23
SeniorCode#Directives#Components

What happens if you use script tag inside template?

Angular recognizes the value as unsafe and automatically sanitizes it, which removes the script tag but keeps safe content such as the text content of the script tag. This way it eliminates the risk of script injection attacks. If you still use it then it will be ignored and a warning appears in the browser console.

24
SeniorCode#Directives#Components

What is interpolation?

Interpolation is a special syntax that Angular converts into property binding. It’s a convenient alternative to property binding. It is represented by double curly braces({{}}). The text between the braces is often the name of a component property. Angular replaces that name with the string value of the corresponding component property.

25
SeniorCode#Directives#Components

What are template expressions?

A template expression in Angular produces a value similar to any JavaScript expression. Angular executes the expression during change detection and assigns the computed result to a property of a binding target—such as an HTML element attribute, a component @Input(), or a directive property.

26
SeniorCode#Directives#Components

What are template statements?

A template statement responds to an event raised by a binding target, such as an HTML element, component output (@Output()), or directive. Template statements appear in quotes to the right of the (event) symbol in event binding syntax: (event)="statement".

27
SeniorCode#Directives#Components

How do you categorize data binding types?

Binding types can be grouped into three categories distinguished by the direction of data flow. They are listed as below: From the source-to-view • From view-to-source • View-to-source-to-view.

28
SeniorCode#Directives#Components

What are pipes?

Pipes are simple functions that use template expressions to accept data as input and transform it into a desired output. For example, let us take a pipe to transform a component's birthday property into a human-friendly date using date pipe.

29
SeniorCode#Directives#Components

What is a parameterized pipe?

A pipe can accept any number of optional parameters to fine-tune its output. The parameterized pipe can be created by declaring the pipe name with a colon ( : ) and then the parameter value. If the pipe accepts multiple parameters, separate the values with colons. Let's take a birthday example with a particular format(dd/MM/yyyy).

30
SeniorCode#Directives#Components

How do you chain pipes?

You can chain pipes together in potentially useful combinations as per the needs. Let's take a birthday property which uses date pipe(along with parameter) and uppercase pipes as below.

31
SeniorCode#Directives#Components

What is a custom pipe?

Apart from built-in pipes, you can write your own custom pipe with the below key characteristics: A pipe is a class decorated with pipe metadata @Pipe decorator, which you import from the core Angular library.

32
SeniorCode#Directives#Components

Give an example of custom pipe?

You can create custom reusable pipes for the transformation of existing value. For example, let us create a custom pipe for finding file size based on an extension, Now you can use the above pipe in template expression as below.

33
SeniorCode#Directives#Components

What is the difference between pure and impure pipe?

A pure pipe is only called when Angular detects a change in the value or the parameters passed to a pipe. For example, any changes to a primitive input value (String, Number, Boolean, Symbol) or a changed object reference (Date, Array, Function, Object).

34
SeniorCode#Directives#Components

What is a bootstrapping module?

Every application has at least one Angular module, the root module that you bootstrap to launch the application is called as bootstrapping module. It is commonly known as AppModule. The default structure of AppModule generated by AngularCLI would be as follows.

35
SeniorCode#Directives#RxJS

What are observables?

Observables are declarative which provide support for passing messages between publishers and subscribers in your application. They are mainly used for event handling, asynchronous programming, and handling multiple values. In this case, you define a function for publishing values, but it is not executed until a consumer subscribes to it.

Part 2: HttpClient, RxJS Observables & Angular Elements (36 - 62)

27 Questions
36
Most AskedJuniorCode#CLI#RxJS

What is HttpClient and its benefits?

Most of the Front-end applications communicate with backend services over HTTP protocol using either XMLHttpRequest interface or the fetch() API. Angular provides a simplified client HTTP API known as HttpClient which is based on top of XMLHttpRequest interface. This client is available from @angular/common/http package.

37
Most AskedMidCode#CLI#RxJS

Explain on how to use HttpClient with an example?

Below are the steps need to be followed for the usage of HttpClient.

38
Most AskedMidCode#CLI#RxJS

How can you read full response?

The response body doesn't or may not return full response data because sometimes servers also return special headers or status code, which are important for the application workflow. In order to get the full response, you should use observe option from HttpClient.

39
Most AskedMidCode#CLI#RxJS

How do you perform Error handling?

If the request fails on the server or fails to reach the server due to network issues, then HttpClient will return an error object instead of a successful response. In this case, you need to handle in the component by passing error object as a second callback to subscribe() method.

40
Most AskedJuniorCode#CLI#RxJS

What is RxJS?

RxJS is a library for composing asynchronous and callback-based code in a functional, reactive style using Observables. Many APIs such as HttpClient produce and consume RxJS Observables and also uses operators for processing observables.

41
Most AskedJuniorCode#CLI#RxJS

What is subscribing?

An Observable instance begins publishing values only when someone subscribes to it. So you need to subscribe by calling the subscribe() method of the instance, passing an observer object to receive the notifications.

42
Most AskedJuniorCode#CLI#RxJS

What is an observable?

An Observable is a unique Object similar to a Promise that can help manage async code. Observables are not part of the JavaScript language so we need to rely on a popular Observable library called RxJS. The observables are created using new keyword.

43
Most AskedJuniorCode#CLI#RxJS

What is an observer?

Observer is an interface for a consumer of push-based notifications delivered by an Observable. It has below structure.

44
Most AskedJuniorCode#CLI#RxJS

What is the difference between promise and observable?

Below are the list of differences between promise and observable.

45
Most AskedSeniorCode#CLI#RxJS

What is multicasting?

Multi-casting is the practice of broadcasting to a list of multiple subscribers in a single execution.

46
Most AskedMidCode#CLI#RxJS

How do you perform error handling in observables?

You can handle errors by specifying an error callback on the observer instead of relying on try/catch, which are ineffective in asynchronous environment.

47
Most AskedJuniorCode#CLI#RxJS

What is the shorthand notation for subscribe method?

The subscribe() method can accept callback function definitions in line, for next, error, and complete handlers. It is known as shorthand notation or Subscribe method with positional arguments.

48
Most AskedJuniorCode#CLI#RxJS

What are the utility functions provided by RxJS?

The RxJS library also provides below utility functions for creating and working with observables.

49
Most AskedJuniorCode#CLI#RxJS

What are observable creation functions?

RxJS provides creation functions for the process of creating observables from promises, events, timers and Ajax requests. Let us explain each of them with an example: Create an observable from a promise.

50
Most AskedMidCode#CLI#RxJS

What will happen if you do not supply handler for the observer?

Usually, an observer object can define any combination of next, error, and complete notification type handlers. If you don't supply a handler for a notification type, the observer just ignores notifications of that type.

51
Most AskedJuniorCode#CLI#RxJS

What are Angular elements?

Angular elements are Angular components packaged as custom elements (a web standard for defining new HTML elements in a framework-agnostic way).

52
Most AskedJuniorCode#CLI#RxJS

What is the browser support of Angular Elements?

Since Angular elements are packaged as custom elements the browser support of angular elements is same as custom elements support.

53
Most AskedJuniorCode#CLI#RxJS

What are custom elements?

Custom elements (or Web Components) are a Web Platform feature which extends HTML by allowing you to define a tag whose content is created and controlled by JavaScript code. The browser maintains a CustomElementRegistry of defined custom elements, which maps an instantiable JavaScript class to an HTML tag.

54
Most AskedMidCode#CLI#RxJS

Do I need to bootstrap custom elements?

No, custom elements bootstrap (or start) automatically when they are added to the DOM, and are automatically destroyed when removed from the DOM. Once a custom element is added to the DOM for any page, it looks and behaves like any other HTML element, and does not require any special knowledge of Angular.

55
Most AskedSeniorCode#CLI#RxJS

Explain how custom elements works internally?

App registers custom element with browser: Use the createCustomElement() function to convert a component into a class that can be registered • App adds custom element to DOM: Add custom element just like a built-in HTML element directly into the DOM.

56
Most AskedMidCode#CLI#RxJS

How to transfer components to custom elements?

Transforming components to custom elements involves two major steps: Build custom element class: Angular provides the createCustomElement() function for converting an Angular component (along with its.

57
Most AskedJuniorCode#CLI#RxJS

What are the mapping rules between Angular component and custom element?

The Component properties and logic maps directly into HTML attributes and the browser's event system. Let us describe them in two steps: The createCustomElement() API parses the component input properties with corresponding attributes for the custom element.

58
Most AskedJuniorCode#CLI#RxJS

How do you define typings for custom elements?

You can use the NgElement and WithProperties types exported from @angular/elements.

59
Most AskedJuniorCode#CLI#RxJS

What are dynamic components?

Dynamic components are the components in which the component's location in the application is not defined at build time i.e. they are not used in any angular template. Instead, the component is instantiated and placed in the application at runtime.

60
Most AskedJuniorCode#Directives#CLI

What are the various kinds of directives?

Components — These are directives with a template • Structural directives — These directives change the DOM layout by adding and removing DOM elements • Attribute directives — These directives change the appearance or behavior of an element, component, or another directive.

61
Most AskedJuniorCode#Directives#CLI

How do you create directives using CLI?

You can use CLI command ng generate directive to create the directive class file. It creates the source file(src/app/components/directivename.directive.ts), the respective test file .spec.ts and declare the directive class file in root module.

62
Most AskedMidCode#Directives#CLI

Give an example for attribute directives?

Let's take simple highlighter behavior as a example directive for DOM element. You can create and apply the attribute directive using below step: Create HighlightDirective class with the file name src/app/highlight.directive.ts • Apply the attribute directive as an attribute to the host element(for example, ).

Part 3: Angular Router, Navigation & SSR Universal (63 - 75)

13 Questions
63
JuniorCode#Routing#SSR & Hydration

What is Angular Router?

Angular Router is a mechanism in which navigation happens from one view to the next as users perform application tasks. It borrows the concepts or model of browser's application navigation. It enables developers to build Single Page Applications with multiple views and allow navigation between these views.

64
JuniorCode#Routing#SSR & Hydration

What is the purpose of base href tag?

The routing application should add element to the index.html as the first child in the tag in order to indicate how to compose navigation URLs. If app folder is the application root then you can set the href value as below.

65
JuniorCode#Routing#SSR & Hydration

What are the router imports?

The Angular Router which represents a particular component view for a given URL is not part of Angular Core. It is available in library named @angular/router to import required router components. For example, we import them in app module as below.

66
JuniorCode#Routing#SSR & Hydration

What is router outlet?

The RouterOutlet is a directive from the router library and it acts as a placeholder that marks the spot in the template where the router should display the components for that outlet. Router outlet is used like a component.

67
JuniorCode#Routing#SSR & Hydration

What are router links?

The RouterLink is a directive on the anchor tags give the router control over those elements. Since the navigation paths are fixed, you can assign string values to router-link directive as below.

68
JuniorCode#Routing#SSR & Hydration

What are active router links?

RouterLinkActive is a directive that toggles css classes for active RouterLink bindings based on the current RouterState. i.e, The Router will add CSS classes when this link is active and remove when the link is inactive. For example, you can add them to RouterLinks as below.

69
JuniorCode#Routing#SSR & Hydration

What is router state?

RouterState is a tree of activated routes. Every node in this tree knows about the "consumed" URL segments, the extracted parameters, and the resolved data. You can access the current RouterState from anywhere in the application using the Router service and the routerState property.

70
JuniorCode#Routing#SSR & Hydration

What are router events?

During each navigation, the Router emits navigation events through the Router.events property allowing you to track the lifecycle of the route.

71
JuniorCode#Routing#SSR & Hydration

What is activated route?

ActivatedRoute contains the information about a route associated with a component loaded in an outlet. It can also be used to traverse the router state tree. The ActivatedRoute will be injected as a router service to access the information. In the below example, you can access route path and parameters.

72
JuniorCode#Routing#SSR & Hydration

How do you define routes?

A router must be configured with a list of route definitions. You configures the router with routes via the RouterModule.forRoot() method, and adds the result to the AppModule's imports array.

73
JuniorCode#Routing#SSR & Hydration

What is the purpose of Wildcard route?

If the URL doesn't match any predefined routes then it causes the router to throw an error and crash the app. In this case, you can use wildcard route. A wildcard route has a path consisting of two asterisks to match every URL.

74
MidCode#Routing#SSR & Hydration

Do I need a Routing Module always?

No, the Routing Module is a design choice. You can skip routing Module (for example, AppRoutingModule) when the configuration is simple and merge the routing configuration directly into the companion module (for example, AppModule).

75
JuniorCode#Routing#SSR & Hydration

What is Angular Universal?

Angular Universal is a server-side rendering module for Angular applications in various scenarios. This is a community driven project and available under @angular/platform-server package. Recently Angular Universal is integrated with Angular CLI.

Part 4: JIT vs AOT Compilation, Metadata & TypeScript (76 - 100)

25 Questions
76
JuniorCode#TypeScript

What are different types of compilation in Angular?

Angular offers two ways to compile your application: Just-in-Time (JIT) • Ahead-of-Time (AOT).

77
JuniorCode#TypeScript

What is JIT?

Just-in-Time (JIT) is a type of compilation that compiles your app in the browser at runtime. JIT compilation was the default until Angular 8, now default is AOT.

78
JuniorCode#TypeScript

What is AOT?

Ahead-of-Time (AOT) is a type of compilation that compiles your app at build time. This is the default starting in Angular 9.

79
MidCode#TypeScript

Why do we need compilation process?

The Angular components and templates cannot be understood by the browser directly. Due to that Angular applications require a compilation process before they can run in a browser. For example, In AOT compilation, both Angular HTML and TypeScript code converted into efficient JavaScript code during the build phase before browser runs it.

80
JuniorCode#TypeScript

What are the advantages with AOT?

Faster rendering: The browser downloads a pre-compiled version of the application • Fewer asynchronous requests: It inlines external HTML templates and CSS style sheets within the application javascript which eliminates separate • Smaller Angular framework download size: Doesn't require downloading the Angular compiler.

81
JuniorCode#TypeScript

What are the ways to control AOT compilation?

You can control your app compilation in two ways: By providing template compiler options in the tsconfig.json file • By configuring Angular metadata with decorators.

82
JuniorCode#TypeScript#HTTP & REST APIs

What are the restrictions of metadata?

In Angular, You must write metadata with the following general constraints: Write expression syntax with in the supported range of javascript features • The compiler can only reference symbols which are exported • Only call the functions supported by the compiler • Decorated and data-bound class members must be public.

83
JuniorCode#TypeScript

What are the three phases of AOT?

The AOT compiler works in three phases: Code Analysis: The compiler records a representation of the source • Code generation: It handles the interpretation as well as places restrictions on what it interprets.

84
MidCode#TypeScript

Can I use arrow functions in AOT?

No, Arrow functions or lambda functions can’t be used to assign values to the decorator properties. For example, the following snippet is invalid.

85
JuniorCode#TypeScript

What is the purpose of metadata json files?

The metadata.json file can be treated as a diagram of the overall structure of a decorator's metadata, represented as an abstract syntax tree(AST).

86
JuniorCode#TypeScript

Can I use any javascript feature for expression syntax in AOT?

No, the AOT collector understands a subset of (or limited) JavaScript features. If an expression uses unsupported syntax, the collector writes an error node to the .metadata.json file. Later point of time, the compiler reports an error if it needs that piece of metadata to generate the application code.

87
JuniorCode#TypeScript

What is folding?

The compiler can only resolve references to exported symbols in the metadata. Where as some of the non-exported members are folded while generating the code.

88
JuniorCode#TypeScript

What are macros?

The AOT compiler supports macros in the form of functions or static methods that return an expression in a single return expression. For example, let us take a below macro function.

89
MidCode#TypeScript

Give an example of few metadata errors?

Expression form not supported: Some of the language features outside of the compiler's restricted expression syntax used in angular metadata can • Reference to a local (non-exported) symbol: The compiler encountered a referenced to a locally defined symbol that either wasn't exported or.

90
JuniorCode#TypeScript

What is metadata rewriting?

Metadata rewriting is the process in which the compiler converts the expression initializing the fields such as useClass, useValue, useFactory, and data into an exported variable, which replaces the expression. Remember that the compiler does this rewriting during the emit of the .js file but not in definition files( .d.ts file).

91
MidCode#TypeScript

How do you provide configuration inheritance?

Angular Compiler supports configuration inheritance through extends in the tsconfig.json on angularCompilerOptions. i.e, The configuration from the base file(for example, tsconfig.base.json) are loaded first, then overridden by those in the inheriting config file.

92
SeniorCode#Components#TypeScript

How do you specify angular template compiler options?

The angular template compiler options are specified as members of the angularCompilerOptions object in the tsconfig.json file. These options will be specified adjacent to typescript compiler options.

93
MidCode#Forms#TypeScript

How do you enable binding expression validation?

You can enable binding expression validation explicitly by adding the compiler option fullTemplateTypeCheck in the "angularCompilerOptions" of the project's tsconfig.json. It produces error messages when a type error is detected in a template binding expression.

94
SeniorCode#TypeScript

What is the purpose of any type cast function?

You can disable binding expression type checking using any() type cast function(by surrounding the expression). In the following example, the error Property contacts does not exist is suppressed by casting user to the any type. The any() cast function also works with this to allow access to undeclared members of the component.

95
JuniorCode#TypeScript

What is Non null type assertion operator?

You can use the non-null type assertion operator to suppress the Object is possibly 'undefined' error. In the following example, the user and contact properties are always set together, implying that contact is always non-null if user is non-null. The error is suppressed in the example by using contact!.email.

96
JuniorCode#TypeScript

What is type narrowing?

The expression used in an ngIf directive is used to narrow type unions in the Angular template compiler similar to if expression in typescript. So *ngIf allows the typeScript compiler to infer that the data used in the binding expression will never be undefined.

97
MidCode#TypeScript

How do you describe various dependencies in angular application?

The dependencies section of package.json with in an angular application can be divided as follow: Angular packages: Angular core and optional modules; their package names begin @angular/ • Support packages: Third-party libraries that must be present for Angular apps to run.

98
JuniorCode#TypeScript

What is zone?

A Zone is an execution context that persists across async tasks. Angular relies on zone.js to run Angular's change detection processes when native JavaScript operations raise events.

99
JuniorCode#TypeScript

What is the purpose of common module?

The commonly-needed services, pipes, and directives provided by @angular/common module. Apart from these HttpClientModule is available under @angular/common/http.

100
JuniorCode#TypeScript

What is codelyzer?

Codelyzer provides set of tslint rules for static code analysis of Angular TypeScript projects. You can run the static code analyzer over web apps, NativeScript, Ionic etc. Angular CLI has support for this and it can be use as below.

Part 5: Animations, Service Workers, Ivy Engine & Builders (101 - 123)

23 Questions
101
JuniorCode#angular#Animations

What is angular animation?

Angular's animation system is built on CSS functionality in order to animate any property that the browser considers animatable.

102
JuniorCode#angular#Animations

What are the steps to use animation module?

You need to follow below steps to implement animation in your angular project: Enabling the animations module: Import BrowserAnimationsModule to add animation capabilities into your Angular root application module(for.

103
JuniorCode#angular#Animations

What is State function?

Angular's state() function is used to define different states to call at the end of each transition. This function takes two arguments: a unique name like open or closed and a style() function.

104
JuniorCode#angular#Animations

What is Style function?

The style function is used to define a set of styles to associate with a given state name. You need to use it along with state() function to set CSS style attributes. For example, in the close state, the button has a height of 100 pixels, an opacity of 0.8, and a background color of green.

105
JuniorCode#angular#Animations

What is the purpose of animate function?

Angular Animations are a powerful way to implement sophisticated and compelling animations for your Angular single page web application.

106
JuniorCode#angular#Animations

What is transition function?

The animation transition function is used to specify the changes that occur between one state and another over a period of time. It accepts two arguments: the first argument accepts an expression that defines the direction between two transition states, and the second argument accepts an animate() function.

107
MidCode#angular#Animations

How to inject the dynamic script in angular?

Using DomSanitizer we can inject the dynamic Html,Style,Script,Url.

108
JuniorCode#angular#Animations

What is a service worker and its role in Angular?

A service worker is a script that runs in the web browser and manages caching for an application. Starting from 5.0.0 version, Angular ships with a service worker implementation.

109
JuniorCode#angular#Animations

What are the design goals of service workers?

It caches an application just like installing a native application • A running application continues to run with the same version of all files without any incompatible files • When you refresh the application, it loads the latest fully cached version • When changes are published then it immediately updates in the background.

110
Most AskedJuniorCode#Dependency Injection

What are the differences between AngularJS and Angular with respect to dependency injection?

Dependency injection is a common component in both AngularJS and Angular, but there are some key differences between the two frameworks in how it actually works.

111
JuniorCode#angular#Animations

What is Angular Ivy?

Angular Ivy is a new rendering engine for Angular. You can choose to opt in a preview version of Ivy from Angular version 8.

112
JuniorCode#angular#Animations

What are the features included in ivy preview?

You can expect below features with Ivy preview: Generated code that is easier to read and debug at runtime • Faster re-build time • Improved payload size • Improved template type checking.

113
MidCode#angular#Animations

Can I use AOT compilation with Ivy?

Yes, it is a recommended configuration. Also, AOT compilation with Ivy is faster. So you need set the default build options(with in angular.json) for your project to always use AOT compilation.

114
JuniorCode#angular#Animations

What is Angular Language Service?

The Angular Language Service is a way to get completions, errors, hints, and navigation inside your Angular templates whether they are external in an HTML file or embedded in annotations/decorators in a string.

115
MidCode#angular#Animations

How do you install angular language service in the project?

You can install Angular Language Service in your project with the following npm command.

116
MidCode#angular#Animations

Is there any editor support for Angular Language Service?

Yes, Angular Language Service is currently available for Visual Studio Code and WebStorm IDEs. You need to install angular language service using an extension and devDependency respectively. In sublime editor, you need to install typescript which has has a language service plugin model.

117
MidCode#angular#Animations

Explain the features provided by Angular Language Service?

Autocompletion: Autocompletion can speed up your development time by providing you with contextual possibilities and hints as you type with in.

118
MidCode#angular#Animations

How do you add web workers in your application?

You can add web worker anywhere in your application. For example, If the file that contains your expensive computation is src/app/app.component.ts, you can add a Web Worker using ng generate web-worker app command which will create src/app/app.worker.ts web worker file.

119
JuniorCode#angular#Animations

What are the limitations with web workers?

You need to remember two important things when using Web Workers in Angular projects: Some environments or platforms(like @angular/platform-server) used in Server-side Rendering, don't support Web Workers • Running Angular in web worker using @angular/platform-webworker is not yet supported in Angular CLI.

120
JuniorCode#CLI

What is Angular CLI Builder?

In Angular8, the CLI Builder API is stable and available to developers who want to customize the Angular CLI by adding or modifying commands. For example, you could supply a builder to perform an entirely new task, or to change which third-party tool is used by an existing command.

121
JuniorCode#angular#Animations

What is a builder?

A builder function is a function that uses the Architect API to perform a complex process such as "build" or "test". The builder code is defined in an npm package. For example, BrowserBuilder runs a webpack build for a browser target and KarmaBuilder starts the Karma server and runs a webpack build for unit tests.

122
MidCode#angular#Animations

How do you invoke a builder?

The Angular CLI command ng run is used to invoke a builder with a specific target configuration. The workspace configuration file, angular.json, contains default configurations for built-in builders.

123
JuniorCode#angular#Animations

How do you create app shell in Angular?

An App shell is a way to render a portion of your application via a route at build time. This is useful to first paint of your application that appears quickly because the browser can render static HTML and CSS without the need to initialize JavaScript.

Part 6: Decorators, Dependency Injection & Tooling (124 - 150)

27 Questions
124
Most AskedJuniorCode#Dependency Injection#TypeScript

What are the case types in Angular?

Angular uses capitalization conventions to distinguish the names of various types. Angular follows the list of the below case types.

125
Most AskedJuniorCode#Dependency Injection#TypeScript

What are the class decorators in Angular?

A class decorator is a decorator that appears immediately before a class definition, which declares the class to be of the given type, and provides metadata suitable to the type.

126
Most AskedJuniorCode#Dependency Injection#TypeScript

What are class field decorators?

The class field decorators are the statements declared immediately before a field in a class definition that defines the type of that field. Some of the examples are: @input and @output.

127
Most AskedJuniorCode#Dependency Injection#TypeScript

What is declarable in Angular?

Declarable is a class type that you can add to the declarations list of an NgModule. The class types such as components, directives, and pipes comes can be declared in the module. The structure of declarations would be.

128
Most AskedJuniorCode#Dependency Injection#TypeScript

What are the restrictions on declarable classes?

A class that's already declared in another NgModule • Ngmodule classes • Service classes • Helper classes.

129
Most AskedJuniorCode#Dependency Injection#TypeScript

What is a DI token?

A DI token is a lookup token associated with a dependency provider in dependency injection system. The injector maintains an internal token-provider map that it references when asked for a dependency and the DI token is the key to the map. Let's take example of DI Token usage.

130
Most AskedJuniorCode#Dependency Injection#TypeScript

What is Angular DSL?

A domain-specific language (DSL) is a computer language specialized to a particular application domain. Angular has its own Domain Specific Language (DSL) which allows us to write Angular specific html-like syntax on top of normal html. It has its own compiler that compiles this syntax to html that the browser can understand.

131
Most AskedJuniorCode#RxJS#Dependency Injection

What is an RxJS Subject in Angular?

An RxJS Subject is a special type of Observable that allows values to be multicasted to many Observers. While plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable), Subjects are multicast.

132
Most AskedJuniorCode#Dependency Injection#TypeScript

What is Bazel tool?

Bazel is a powerful build tool developed and massively used by Google and it can keep track of the dependencies between different packages and build targets. In Angular8, you can build your CLI application with Bazel. Note: The Angular framework itself is built with Bazel.

133
Most AskedJuniorCode#Dependency Injection#TypeScript

What are the advantages of Bazel tool?

It creates the possibility of building your back-ends and front-ends with the same tool • The incremental build and tests • It creates the possibility to have remote builds and cache on a build farm.

134
Most AskedMidCode#CLI#Dependency Injection

How do you use Bazel with Angular CLI?

The @angular/bazel package provides a builder that allows Angular CLI to use Bazel as the build tool.

135
Most AskedMidCode#Dependency Injection#TypeScript

How do you run Bazel directly?

Sometimes you may want to bypass the Angular CLI builder and run Bazel directly using Bazel CLI. You can install it globally using @bazel/bazel npm package. i.e, Bazel CLI is available under @bazel/bazel package. After you can apply the below common commands.

136
Most AskedJuniorCode#Dependency Injection#Forms

What is platform in Angular?

A platform is the context in which an Angular application runs. The most common platform for Angular applications is a web browser, but it can also be an operating system for a mobile device, or a web server.

137
Most AskedMidCode#Dependency Injection#TypeScript

What happens if I import the same module twice?

If multiple modules imports the same module then angular evaluates it only once (When it encounters the module first time). It follows this condition even the module appears at any level in a hierarchy of imported NgModules.

138
Most AskedMidCode#Dependency Injection#Components

How do you select an element with in a component template?

You can use @ViewChild directive to access elements in the view directly. Let's take input element with a reference.

139
Most AskedMidCode#Dependency Injection#TypeScript

How do you detect route change in Angular?

In Angular7, you can subscribe to router to detect the changes. The subscription for router events would be as below.

140
Most AskedMidCode#CLI#Dependency Injection

How do you pass headers for HTTP client?

You can directly pass object map for http client or create HttpHeaders class to supply the headers.

141
Most AskedJuniorCode#CLI#Dependency Injection

What is the purpose of differential loading in CLI?

From Angular8 release onwards, the applications are built using differential loading strategy from CLI to build two separate bundles as part of your deployed application.

142
Most AskedMidCode#Dependency Injection#TypeScript

Does Angular support dynamic imports?

Yes, Angular 8 supports dynamic imports in router configuration. i.e, You can use the import statement for lazy loading the module using loadChildren method and it will be understood by the IDEs(VSCode and WebStorm), webpack, etc. Previously, you have been written as below to lazily load the feature module.

143
Most AskedJuniorCode#Dependency Injection#Routing

What is lazy loading?

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.

144
Most AskedJuniorCode#Dependency Injection#TypeScript

What are workspace APIs?

Angular 8.0 release introduces Workspace APIs to make it easier for developers to read and modify the angular.json file instead of manually modifying it. Currently, the only supported storage3 format is the JSON-based format used by the Angular CLI. You can enable or add optimization option for build target as below.

145
Most AskedMidCode#Dependency Injection#TypeScript

How do you upgrade angular version?

The Angular upgrade is quite easier using Angular CLI ng update command as mentioned below. For example, if you upgrade from Angular 7 to 8 then your lazy loaded route imports will be migrated to the new import syntax automatically.

146
Most AskedJuniorCode#Dependency Injection#TypeScript

What is Angular Material?

Angular Material is a collection of Material Design components for Angular framework following the Material Design spec. You can apply Material Design very easily using Angular Material. The installation can be done through npm or yarn, It supports the most recent two versions of all major browsers.

147
Most AskedMidCode#Dependency Injection#TypeScript

How do you upgrade location service of angularjs?

If you are using location service in your old AngularJS application, now you can use LocationUpgradeModule(unified location service) which puts the responsibilities of location service to Location service in Angular. Let's add this module to AppModule as below.

148
Most AskedJuniorCode#Dependency Injection#TypeScript

What is NgUpgrade?

NgUpgrade is a library put together by the Angular team, which you can use in your applications to mix and match AngularJS and Angular components and bridge the AngularJS and Angular dependency injection systems.

149
Most AskedMidCode#CLI#Dependency Injection

How do you test Angular application using CLI?

Angular CLI downloads and install everything needed with the Jasmine Test framework. You just need to run ng test to see the test results. By default this command builds the app in watch mode, and launches the Karma test runner.

150
Most AskedMidCode#Dependency Injection#TypeScript

How to use polyfills in Angular application?

The Angular CLI provides support for polyfills officially. 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.

Part 7: Change Detection, Security (XSS/Sanitizer) & Interceptors (151 - 176)

26 Questions
151
Most AskedJuniorCode#Change Detection#Security & Auth

What are the ways to trigger change detection in Angular?

ApplicationRef.tick(): Invoke this method to explicitly process change detection and its side-effects • NgZone.run(callback): It evaluate the callback function inside the Angular zone • ChangeDetectorRef.detectChanges(): It detects only the components and it's children.

152
Most AskedJuniorCode#Change Detection#Security & Auth

What are the differences of various versions of Angular?

Angular 1 • Angular 1 (AngularJS) is the first angular framework released in the year 2010 • AngularJS is not built for mobile devices • It is based on controllers with MVC architecture.

153
Most AskedJuniorCode#Change Detection#Security & Auth

What are the security principles in angular?

You should avoid direct use of the DOM APIs • You should enable Content Security Policy (CSP) and configure your web server to return appropriate CSP HTTP headers • You should Use the offline template compiler • You should Use Server Side XSS protection.

154
Most AskedJuniorCode#Change Detection#Security & Auth

What is the reason to deprecate Web Tracing Framework?

Angular has supported the integration with the Web Tracing Framework (WTF) for the purpose of performance testing. Since it is not well maintained and failed in majority of the applications, the support is deprecated in latest releases.

155
Most AskedJuniorCode#Change Detection#Security & Auth

What is the reason to deprecate web worker packages?

Both @angular/platform-webworker and @angular/platform-webworker-dynamic are officially deprecated, the Angular team realized it's not good practice to run the Angular application on Web worker.

156
Most AskedMidCode#CLI#Change Detection

How do you find angular CLI version?

Angular CLI provides it's installed version using below different ways using ng command.

157
Most AskedJuniorCode#Change Detection#Security & Auth

What is the browser support for Angular?

Angular supports most recent browsers which includes both desktop and mobile browsers. As of Angular 13+, IE is no longer supported.

158
Most AskedJuniorCode#Change Detection#Security & Auth

What is schematic?

It's a scaffolding library that defines how to generate or transform a programming project by creating, modifying, refactoring, or moving files and code. It defines rules that operate on a virtual file system called a tree.

159
Most AskedJuniorCode#Change Detection#Security & Auth

What is rule in Schematics?

In schematics world, it's a function that operates on a file tree to create, delete, or modify files in a specific manner.

160
Most AskedJuniorCode#CLI#Change Detection

What is Schematics CLI?

Schematics come with their own command-line tool known as Schematics CLI. It is used to install the schematics executable, which you can use to create a new schematics collection with an initial named schematic. The collection folder is a workspace for schematics.

161
Most AskedJuniorCode#Change Detection#Security & Auth

What are the best practices for security in angular?

Use the latest Angular library releases • Don't modify your copy of Angular • Avoid Angular APIs marked in the documentation as “Security Risk.”.

162
Most AskedJuniorCode#Change Detection#Security & Auth

What is Angular security model for preventing XSS attacks?

Angular treats all values as untrusted by default. i.e, Angular sanitizes and escapes untrusted values When a value is inserted into the DOM from a template, via property, attribute, style, class binding, or interpolation.

163
Most AskedSeniorCode#Components#Change Detection

What is the role of template compiler for prevention of XSS attacks?

The offline template compiler prevents vulnerabilities caused by template injection, and greatly improves application performance. So it is recommended to use offline template compiler in production deployments without dynamically generating any template.

164
Most AskedJuniorCode#Change Detection#Security & Auth

What are the various security contexts in Angular?

Angular defines the following security contexts for sanitization: HTML: It is used when interpreting a value as HTML such as binding to innerHtml • Style: It is used when binding CSS into the style property • URL: It is used for URL properties such as ` • Resource URL: It is a URL that will be loaded and executed as code such as `.

165
Most AskedJuniorCode#Change Detection#Security & Auth

What is Sanitization? Does Angular support it?

Sanitization is the inspection of an untrusted value, turning it into a value that's safe to insert into the DOM. Yes, Angular supports sanitization. It sanitizes untrusted values for HTML, styles, and URLs but sanitizing resource URLs isn't possible because they contain arbitrary code.

166
Most AskedJuniorCode#Change Detection#Security & Auth

What is the purpose of innerHTML?

The innerHtml is a property of HTML-Elements, which allows you to set it's html-content programmatically. Let's display the below html code snippet in a `` tag as below using innerHTML binding.

167
Most AskedJuniorCode#Change Detection#Security & Auth

What is the difference between interpolated content and innerHTML?

The main difference between interpolated and innerHTML code is the behavior of code interpreted. Interpolated content is always escaped i.e, HTML isn't interpreted and the browser displays angle brackets in the element's text content.

168
Most AskedMidCode#Change Detection#Security & Auth

How do you prevent automatic sanitization?

Sometimes the applications genuinely need to include executable code such as displaying `` from an URL. In this case, you need to prevent automatic sanitization in Angular by saying that you inspected a value, checked how it was generated, and made sure it will always be secure.

169
Most AskedMidCode#Change Detection#Security & Auth

Is it safe to use direct DOM API methods in terms of security?

No,the built-in browser DOM APIs or methods don't automatically protect you from security vulnerabilities. In this case it is recommended to use Angular templates instead of directly interacting with DOM. If it is unavoidable then use the built-in Angular sanitization functions.

170
Most AskedJuniorCode#Change Detection#Security & Auth

What is DOM sanitizer?

DomSanitizer is used to help preventing Cross Site Scripting Security bugs (XSS) by sanitizing values to be safe to use in the different DOM contexts.

171
Most AskedMidCode#Change Detection#Security & Auth

How do you support server side XSS protection in Angular application?

The server-side XSS protection is supported in an angular application by using a templating language that automatically escapes values to prevent XSS vulnerabilities on the server.

172
Most AskedMidCode#Change Detection#Security & Auth

Does Angular prevent HTTP level vulnerabilities?

Angular has built-in support for preventing http level vulnerabilities such as as cross-site request forgery (CSRF or XSRF) and cross-site script inclusion (XSSI). Even though these vulnerabilities need to be mitigated on server-side, Angular provides helpers to make the integration easier on the client side.

173
Most AskedJuniorCode#Change Detection#Security & Auth

What are Http Interceptors?

Http Interceptors are part of @angular/common/http, which inspect and transform HTTP requests from your application to the server and vice-versa on HTTP responses. These interceptors can perform a variety of implicit tasks, from authentication to logging.

174
Most AskedJuniorCode#Change Detection#Security & Auth

What are the applications of HTTP interceptors?

The HTTP Interceptors can be used for different variety of tasks: Authentication • Logging • Caching • Fake backend.

175
Most AskedMidCode#Change Detection#Security & Auth

Are multiple interceptors supported in Angular?

Yes, Angular supports multiple interceptors at a time. You could define multiple interceptors in providers property: The interceptors will be called in the order in which they were provided. i.e, MyFirstInterceptor will be called first in the above interceptors configuration.

176
Most AskedMidCode#Change Detection#Security & Auth

How can I use interceptor for an entire application?

You can use same instance of HttpInterceptors for the entire app by importing the HttpClientModule only in your AppModule, and add the interceptors to the root application injector. For example, let's define a class that is injectable in root application. After that import HttpClientModule in AppModule.

Part 8: Internationalization (i18n), Testing & DOM Directives (177 - 212)

36 Questions
177
MidCode#Directives#Testing

How does Angular simplify Internationalization?

Displaying dates, number, percentages, and currencies in a local format • Preparing text in component templates for translation • Handling plural forms of words • Handling alternative text.

178
MidCode#Directives#Testing

How do you manually register locale data?

By default, Angular only contains locale data for en-US which is English as spoken in the United States of America . But if you want to set to another locale, you must import locale data for that new locale.

179
JuniorCode#Directives#Components

What are the four phases of template translation?

The i18n template translation process has four phases: Mark static text messages in your component templates for translation: You can place i18n on every element tag whose fixed text is to be translated.

180
JuniorCode#Directives#Testing

What is the purpose of i18n attribute?

The Angular i18n attribute marks translatable content. It is a custom attribute, recognized by Angular tools and compilers. The compiler removes it after translation.

181
JuniorCode#Directives#Testing

What is the purpose of custom id?

When you change the translatable text, the Angular extractor tool generates a new id for that translation unit. Because of this behavior, you must then update the translation file with the new id every time.

182
MidCode#Directives#Testing

What happens if the custom id is not unique?

You need to define custom ids as unique. If you use the same id for two different text messages then only the first one is extracted. But its translation is used in place of both original text messages.

183
MidCode#Directives#Testing

Can I translate text without creating an element?

Yes, you can achieve using attribute. Normally you need to wrap a text content with i18n attribute for the translation. But if you don't want to create a new DOM element just for the sake of translation, you can wrap the text in an element. Remember that is transformed into an html comment.

184
MidCode#Directives#Testing

How can I translate attribute?

You can translate attributes by attaching i18n-x attribute where x is the name of the attribute to translate. For example, you can translate image title attribute as below, By the way, you can also assign meaning, description and id with the i18n-x="@@" syntax.

185
MidCode#Directives#Testing

List down the pluralization categories?

Pluralization has below categories depending on the language.

186
JuniorCode#Directives#Testing

What is select ICU expression?

ICU expression is is similar to the plural expressions except that you choose among alternative translations based on a string value instead of a number. Here you define those string values.

187
MidCode#Directives#Testing

How do you report missing translations?

By default, When translation is missing, it generates a warning message such as "Missing translation for message 'somekey'". But you can configure with a different level of message in Angular compiler as below: Error: It throws an error • Warning (default): It shows a 'Missing translation' warning in the console or shell.

188
MidCode#Directives#Testing

How do you provide build configuration for multiple locales?

You can provide build configuration such as translation file path, name, format and application url in configuration settings of Angular.json file. For example, the German version of your application configured the build as follows.

189
JuniorCode#Directives#Testing

What is an angular library?

An Angular library is an Angular project that differs from an app in that it cannot run on its own. It must be imported and used in an app. For example, you can import or add service worker library to an Angular application which turns an application into a Progressive Web App (PWA).

190
SeniorCode#Directives#Testing

What is AOT compiler?

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.

191
MidCode#Directives#Components

How do you select an element in component template?

You can control any DOM element via ElementRef by injecting it into your component's constructor. i.e, The component should have constructor with ElementRef parameter.

192
JuniorCode#Directives#Testing

What is TestBed?

TestBed is an api for writing unit tests for Angular applications and it's libraries. Even though We still write our tests in Jasmine and run using Karma, this API provides an easier way to create components, handle injection, test asynchronous behaviour and interact with our application.

193
JuniorCode#Directives#Testing

What is protractor?

Protractor is an end-to-end test framework for Angular and AngularJS applications. It runs tests against your application running in a real browser, interacting with it as a user would.

194
JuniorCode#Directives#Testing

What is collection?

Collection is a set of related schematics collected in an npm package. For example, @schematics/angular collection is used in Angular CLI to apply transforms to a web-app project. You can create your own schematic collection for customizing angular projects.

195
JuniorCode#Directives#Testing

How do you create schematics for libraries?

You can create your own schematic collections to integrate your library with the Angular CLI. These collections are classified as 3 main schematics: Add schematics: These schematics are used to install library in an Angular workspace using ng add command.

196
MidCode#Directives#Testing

How do you use jquery in Angular?

You can use jquery in Angular using 3 simple steps: Install the dependency: At first, install the jquery dependency using npm.

197
JuniorCode#Directives#Testing

What is the reason for No provider for HTTP exception?

This exception is due to missing HttpClientModule in your module. You just need to import in module as below.

198
JuniorCode#Directives#Routing

What is router state?

The RouteState is an interface which represents the state of the router as a tree of activated routes. You can access the current RouterState from anywhere in the Angular app using the Router service and the routerState property.

199
MidCode#Directives#Testing

How can I use SASS in angular project?

When you are creating your project with angular cli, you can use ng newcommand. It generates all your components with predefined sass files. But if you are changing your existing style in your project then use ng set command.

200
JuniorCode#Directives#Testing

What is the purpose of hidden property?

The hidden property is used to show or hide the associated DOM element, based on an expression. It can be compared close to ng-show directive in AngularJS. Let's say you want to show user name based on the availability of user using hidden property.

201
JuniorCode#Directives#Testing

What is the difference between ngIf and hidden property?

Both *ngIf (or modern @if) and the HTML [hidden] property control whether content is visible to the user, but they work through fundamentally different mechanisms with significant performance and lifecycle implications.

202
JuniorCode#Directives#Pipes

What is slice pipe?

The slice pipe is used to create a new Array or String containing a subset (slice) of the elements. The syntax looks like as below, For example, you can provide 'hello' list based on a greeting array.

203
Most AskedJuniorCode#Directives#Testing

What is index property in ngFor directive?

The index property returns the zero-based numeric position of each item during a template iteration. Angular provides contextual variables in both the Classic Built-in Directive (ngFor) and the Modern Built-in Control Flow (@for)**.

204
JuniorCode#Directives#Testing

What is the purpose of ngFor trackBy?

The trackBy function in *ngFor (and mandatory track in @for) is a critical performance optimization mechanism for DOM reconciliation when rendering collections.

205
JuniorCode#Directives#Testing

What is the purpose of ngSwitch directive?

The ngSwitch directive conditionally swaps DOM elements based on a matching expression, functioning like a JavaScript switch statement. Angular supports both the Classic Built-in Directives (ngSwitch, ngSwitchCase, ngSwitchDefault) and the Modern Built-in Control Flow (@switch, @case, @default).

206
MidCode#Directives#Testing

Is it possible to do aliasing for inputs and outputs?

Yes, it is possible to do aliasing for inputs and outputs in two ways.

207
JuniorCode#Directives#Routing

What is safe navigation operator?

The safe navigation operator(?)(or known as Elvis Operator) is used to guard against null and undefined values in property paths when you are not aware whether a path exists or not. i.e. It returns value of the object path if it exists, else it returns the null value.

208
MidCode#Directives#Testing

Is any special configuration required for Angular9?

You don't need any special configuration. In Angular9, the Ivy renderer is the default Angular compiler. Even though Ivy is available Angular8 itself, you had to configure it in tsconfig.json file as below.

209
JuniorCode#Directives#Testing

What are type safe TestBed API changes in Angular9?

Angular 9 provides type safe changes in TestBed API changes by replacing the old get function with the new inject method. Because TestBed.get method is not type-safe. The usage would be as below.

210
MidCode#Directives#Testing

Is mandatory to pass static flag for ViewChild?

In Angular 8, the static flag is required for ViewChild. Whereas in Angular9, you no longer need to pass this property. Once you updated to Angular9 using ng update, the migration will remove { static: false } script everywhere.

211
JuniorCode#Directives#Components

What are the list of template expression operators?

The Angular template expression language supports three special template expression operators.

212
JuniorCode#Directives#Pipes

What is the precedence between pipe and ternary operators?

The pipe operator has a higher precedence than the ternary operator (?:). For example, the expression first ? second : third fourth is parsed as first ? second : (third fourth).

Part 9: NgModules, Providers, NgZone & Injector Hierarchies (213 - 255)

43 Questions
213
JuniorCode#Dependency Injection#Components

What is an entry component?

An entry component is any component that Angular loads imperatively(i.e, not referencing it in the template) by type. Due to this behavior, they can’t be found by the Angular compiler during compilation. These components created dynamically with ComponentFactoryResolver.

214
JuniorCode#Dependency Injection#Components

What is a bootstrapped component?

A bootstrapped component is an entry component that Angular loads into the DOM during the bootstrap process or application launch time. Generally, this bootstrapped or root component is named as AppComponent in your root module using bootstrap property as below.

215
MidCode#Dependency Injection

How do you manually bootstrap an application?

You can use ngDoBootstrap hook for a manual bootstrapping of the application instead of using bootstrap array in @NgModule annotation. This hook is part of DoBootstrap interface. The module needs to be implement the above interface to use the hook for bootstrapping.

216
MidCode#Dependency Injection#Components

Is it necessary for bootstrapped component to be entry component?

Yes, the bootstrapped component needs to be an entry component. This is because the bootstrapping process is an imperative process.

217
JuniorCode#Dependency Injection#Components

What is a routed entry component?

The components referenced in router configuration are called as routed entry components. This routed entry component defined in a route definition as below, Since router definition requires you to add the component in two places (router and entryComponents), these components are always entry components.

218
MidCode#Dependency Injection#Components

Why is not necessary to use entryComponents array every time?

Most of the time, you don't need to explicitly to set entry components in entryComponents array of ngModule decorator. Because angular adds components from both @NgModule.bootstrap and route definitions to entry components automatically.

219
MidCode#Dependency Injection#Components

Do I still need to use entryComponents array in Angular9?

No. In previous angular releases, the entryComponents array of ngModule decorator is used to tell the compiler which components would be created and inserted dynamically in the view. In Angular9, this is not required anymore with Ivy.

220
MidCode#Dependency Injection#Components

Is it all components generated in production build?

No, only the entry components and template components appears in production builds. If a component isn't an entry component and isn't found in a template, the tree shaker will throw it away. Due to this reason, make sure to add only true entry components to reduce the bundle size.

221
SeniorCode#Dependency Injection

What is Angular compiler?

The Angular compiler is used to convert the application code into JavaScript code. It reads the template markup, combines it with the corresponding component class code, and emits component factories which creates JavaScript representation of the component along with elements of @Component metadata.

222
JuniorCode#Dependency Injection

What is the role of ngModule metadata in compilation process?

The @NgModule metadata is used to tell the Angular compiler what components to be compiled for this module and how to link this module with other modules.

223
MidCode#Directives#Dependency Injection

How does angular finds components, directives and pipes?

The Angular compiler finds a component or directive in a template when it can match the selector of that component or directive in that template. Whereas it finds a pipe if the pipe's name appears within the pipe syntax of the template HTML.

224
MidCode#Dependency Injection

Give few examples for NgModules?

The Angular core libraries and third-party libraries are available as NgModules.

225
JuniorCode#Dependency Injection

What are feature modules?

Feature modules are NgModules, which are used for the purpose of organizing code. The feature module can be created with Angular CLI using the below command in the root directory, Angular CLI creates a folder called my-custom-feature with a file inside called my-custom-feature.module.ts with the following contents.

226
JuniorCode#CLI#Dependency Injection

What are the imported modules in CLI generated feature modules?

In the CLI generated feature module, there are two JavaScript import statements at the top of the file.

227
JuniorCode#Dependency Injection

What are the differences between ngmodule and javascript module?

Below are the main differences between Angular NgModule and javascript module.

228
JuniorCode#Dependency Injection

What are the possible errors with declarations?

If you use a component without declaring it, Angular returns an error message • If you try to declare the same class in more than one module then compiler emits an error.

229
JuniorCode#Dependency Injection

What are the steps to use declaration elements?

Below are the steps to be followed to use declaration elements.

230
MidCode#Dependency Injection

What happens if browserModule used in feature module?

If you do import BrowserModule into a lazy loaded feature module, Angular returns an error telling you to use CommonModule instead. Because BrowserModule’s providers are for the entire app so it should only be in the root module, not in feature module. Whereas Feature modules only need the common directives in CommonModule.

231
JuniorCode#Dependency Injection

What are the types of feature modules?

Domain: Deliver a user experience dedicated to a particular application domain(For example, place an order, registration etc) • Routed: These are domain feature modules whose top components are the targets of router navigation routes • Routing: It provides routing configuration for another module.

232
JuniorCode#Dependency Injection

What is a provider?

A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency(aka services created). The service can be provided using Angular CLI as below, The created service by CLI would be as below.

233
JuniorCode#Dependency Injection

What is the recommendation for provider scope?

You should always provide your service in the root injector unless there is a case where you want the service to be available only if you import a particular @NgModule.

234
MidCode#Dependency Injection#HTTP & REST APIs

How do you restrict provider scope to a module?

It is possible to restrict service provider scope to a specific module instead making available to entire application. There are two possible ways to do it.

235
MidCode#Dependency Injection

How do you provide a singleton service?

Set the providedIn property of the @Injectable() to "root".

236
JuniorCode#Dependency Injection

What are the different ways to remove duplicate service registration?

If a module defines provides and declarations then loading the module in multiple feature modules will duplicate the registration of the service. Below are the different ways to prevent this duplicate behavior.

237
MidCode#Dependency Injection#Routing

How does forRoot method helpful to avoid duplicate router instances?

If the RouterModule module didn’t have forRoot() static method then each feature module would instantiate a new Router instance, which leads to broken application due to duplicate instances.

238
JuniorCode#Dependency Injection

What is a shared module?

The Shared Module is the module in which you put commonly used directives, pipes, and components into one module that is shared(import it) throughout the application.

239
MidCode#Dependency Injection

Can I share services using modules?

No, it is not recommended to share services by importing module. i.e Import modules when you want to use directives, pipes, and components only. The best approach to get a hold of shared services is through 'Angular dependency injection' because importing a module will result in a new service instance.

240
MidCode#Dependency Injection

How do you get current direction for locales?

In Angular 9.1, the API method getLocaleDirection can be used to get the current direction in your app. This method is useful to support Right to Left locales for your Internationalization based applications.

241
JuniorCode#Dependency Injection

What is ngcc?

The ngcc(Angular Compatibility Compiler) is a tool which upgrades nodemodule compiled with non-ivy ngc into ivy compliant format. The postinstall script from package.json will make sure your nodemodules will be compatible with the Ivy renderer.

242
MidCode#Dependency Injection

What classes should not be added to declarations?

The below class types shouldn't be added to declarations: A class which is already declared in any another module • Directives imported from another module • Module classes • Service classes.

243
Most AskedJuniorCode#Dependency Injection

What is NgZone?

Angular provides a service called NgZone which creates a zone named angular to automatically trigger change detection when the following conditions are satisfied.

244
JuniorCode#Dependency Injection

What is NoopZone?

Zone is loaded/required by default in Angular applications and it helps Angular to know when to trigger the change detection. This way, it make sures developers focus on application development rather core part of Angular.

245
JuniorCode#Dependency Injection#Components

How do you create displayBlock components?

By default, Angular CLI creates components in an inline displayed mode(i.e, display:inline).

246
Most AskedJuniorCode#Dependency Injection#Change Detection

What are the possible data update scenarios for change detection?

The change detection works in the following scenarios where the data changes needs to update the application HTML.

247
JuniorCode#Dependency Injection

What is a zone context?

Execution Context is an abstract concept that holds information about the environment within the current code being executed. A zone provides an execution context that persists across asynchronous operations is called as zone context.

248
JuniorCode#Dependency Injection#Hooks

What are the lifecycle hooks of a zone?

There are four lifecycle hooks for asynchronous operations from zone.js.

249
Most AskedJuniorCode#Dependency Injection#Change Detection

What are the methods of NgZone used to control change detection?

NgZone service provides a run() method that allows you to execute a function inside the angular zone. This function is used to execute third party APIs which are not handled by Zone and trigger change detection automatically at the correct time. Whereas runOutsideAngular() method is used when you don't want to trigger change detection.

250
MidCode#Dependency Injection

How do you change the settings of zonejs?

You can change the settings of zone by configuring them in a separate file and import it just after zonejs import. For example, you can disable the requestAnimationFrame() monkey patch to prevent change detection for no data update as one setting and prevent DOM events(a mousemove or scroll event) to trigger change detection.

251
MidCode#Dependency Injection

How do you trigger an animation?

Angular provides a trigger() function for animation in order to collect the states and transitions with a specific animation name, so that you can attach it to the triggering element in the HTML template. This function watch for changes and trigger initiates the actions when a change occurs.

252
MidCode#Dependency Injection

How do you configure injectors with providers at different levels?

You can configure injectors with providers at different levels of your application by setting a metadata value. The configuration can happen in one of three places: In the @Injectable() decorator for the service itself • In the @NgModule() decorator for an NgModule • In the @Component() decorator for a component.

253
MidCode#Dependency Injection

Is it mandatory to use injectable on every service class?

No. The @Injectable() decorator is not strictly required if the class has other Angular decorators on it or does not have any dependencies. But the important thing here is any class that is going to be injected with Angular is decorated.

254
JuniorCode#Dependency Injection

What is an optional dependency?

The optional dependency is a parameter decorator to be used on constructor parameters, which marks the parameter as being an optional dependency. Due to this, the DI framework provides null if the dependency is not found.

255
JuniorCode#Dependency Injection

What are the types of injector hierarchies?

ModuleInjector hierarchy: It configure on a module level using an @NgModule() or @Injectable() annotation • ElementInjector hierarchy: It created implicitly at each DOM element.

Part 10: Reactive Forms, Standalone Components, Signals & NgRx (256 - 283)

28 Questions
256
Most AskedJuniorCode#Signals#Components

What are reactive forms?

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.

257
Most AskedJuniorCode#Signals#Components

What are dynamic forms?

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.

258
Most AskedJuniorCode#Signals#Components

What are template driven forms?

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.

259
Most AskedJuniorCode#Signals#Components

What are the differences between reactive forms and template driven forms?

Below are the main differences between reactive forms and template driven forms.

260
Most AskedJuniorCode#Signals#Components

What are the different ways to group form controls?

Reactive forms provide two ways of grouping multiple related controls.

261
Most AskedMidCode#Signals#Components

How do you update specific properties of a form model?

You can use patchValue() method to update specific properties defined in the form model. For example,you can update the name and street of certain profile on click of the update button as shown below.

262
Most AskedJuniorCode#Signals#Components

What is the purpose of FormBuilder?

FormBuilder is used as syntactic sugar for easily creating instances of a FormControl, FormGroup, or FormArray. This is helpful to reduce the amount of boilerplate needed to build complex reactive forms. It is available as an injectable helper class of the @angular/forms package.

263
Most AskedMidCode#Signals#Components

How do you verify the model changes in forms?

You can add a getter property(let's say, diagnostic) inside component to return a JSON representation of the model during the development. This is useful to verify whether the values are really flowing from the input box to the model and vice versa or not. and add diagnostic binding near the top of the form.

264
Most AskedJuniorCode#Signals#Components

What are the state CSS classes provided by ngModel?

The ngModel directive updates the form control with special Angular CSS classes to reflect it's state. Let's find the list of classes in a tabular format.

265
Most AskedMidCode#Signals#Components

How do you reset the form?

In a model-driven form, you can reset the form just by calling the function reset() on our form model. For example, you can reset the form model on submission as follows, Now, your form model resets the form back to its original pristine state.

266
Most AskedJuniorCode#Signals#Components

What are the types of validator functions?

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.

267
Most AskedMidCode#Signals#Components

Can you give an example of built-in validators?

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 Whereas in template-driven forms, both required and minlength validators available as attributes.

268
Most AskedMidCode#Signals#Components

How do you optimize the performance of async validators?

Since all validators run after every form value change, it creates a major impact on performance with async validators by hitting the external API on each keystroke. This situation can be avoided by delaying the form validity by changing the updateOn property from change (default) to submit or blur.

269
Most AskedMidCode#Signals#Components

How to set ngFor and ngIf on the same element?

In Angular, placing both ngFor and ngIf on the same HTML element is invalid and throws a compile-time template error.

270
Most AskedJuniorCode#Signals#Components

What is host property in css?

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.

271
Most AskedMidCode#Signals#Components

How do you get the current route?

In Angular, there is an url property of router package to get the current route. You need to follow the below few steps: Import Router from @angular/router.

272
Most AskedJuniorCode#Signals#Components

What is Component Test Harnesses?

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.

273
Most AskedJuniorCode#Signals#Components

What is the benefit of Automatic Inlining of Fonts?

During compile time, Angular CLI will download and inline the fonts that your application is using. This performance update speed up the first contentful paint(FCP) and this feature is enabled by default in apps built with version 11.

274
Most AskedJuniorCode#Signals#Components

What is content projection?

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

275
Most AskedJuniorCode#Signals#Components

What is ng-content and its purpose?

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

276
Most AskedJuniorCode#Signals#Components

What is standalone component?

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.

277
Most AskedJuniorCode#CLI#Signals

How to create a standalone component using CLI command?

Generate a standalone component using the CLI command as shown below: On running the command standalone component is created. Here is the list of file created.

278
Most AskedMidCode#Signals#Components

How to create a standalone component manually?

To make existing component to standalone, then add standalone: true in component-name.component.ts as shown below.

279
Most AskedJuniorCode#Signals#Components

What is hydration?

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.

280
Most AskedJuniorCode#Signals#Components

What are Angular Signals?

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.

281
Most AskedMidCode#Signals#Components

Explain Angular Signals with an example.

In this example, we create a signal named count and initialize it with a value of 0. We then connect to the signal, allowing us to be notified whenever its value changes. Finally, we add a button that increments the count when clicked.

282
Most AskedJuniorCode#Signals#Components

What are the Route Parameters? Could you explain each of them?.

Route parameters are used to pass dynamic values in the URL of a route. They allow you to define variable segments in the route path, which can be accessed and used by components and services. Path parameters are represented by a colon (":") followed by the parameter name.

283
Most AskedJuniorCode#Signals#Components

What is NgRx?

NgRx is a framework for building reactive applications in Angular. It is a state management library that provides a Redux-inspired architecture for managing and centralizing application state. NgRx is built on top of RxJS and follows the principles of reactive programming.