
This article summarizes a list of Angular interview questions that I would ask candidates and that I get often asked in interviews.
Angular is an application design framework and development platform for creating efficient and sophisticated single-page apps. Angular is built entirely in TypeScript and uses it as a primary language. As it is a framework it has many useful built-in features like routing, forms, HTTP client, Internationalization (i18n), animations, and many more.
Vue.js and React are no application frameworks but JavaScript libraries to build user interfaces. Vue.js describe itself as an incrementally adoptable ecosystem that scales between a library and a full-featured framework and React as a JavaScript library for building user interfaces.
Check the Angular blog for latest release notes, for example, the Angular 11 release.

Dependency Injection (DI) is an important design pattern in which a class does not create dependencies itself but requests them from external sources. Dependencies are services or objects that a class needs to perform its function. Angular uses its own DI framework for resolving dependencies. The DI framework provides declared dependencies to a class when that class is instantiated.
Angular heavily relies on RxJS, a library for composing asynchronous and callback-based code in a functional, reactive style using Observables. RxJS introduces Observables, a new Push system for JavaScript where an Observable is a producer of multiple values, "pushing" them to Observers (Consumers).
| Observable | Promise |
|---|---|
| They can be run whenever the result is needed as they do not start until subscription | Execute immediately on creation |
| Provides multiple values over time | Provides only one value |
| Subscribe method is used for error handling which makes centralized and predictable error handling | Push errors to the child promises |
| Provides chaining and subscription to handle complex applications | Uses only .then() clause |
@Input() and @Output() directives.<img [src]="itemImageUrl" />
<button (click)="onSave()">Save</button>
<app-sizer [(size)]="fontSizePx"></app-sizer>
Service is a broad category encompassing any value, function, or feature that an app needs. A service is typically a class with a narrow, well-defined purpose. It should do something specific and do it well.
An Angular component should focus on presenting data and enabling the user experience. It should mediate between the application logic (data model) and the view (rendered by the template).
Angular services help us to separate non-view-related functionality to keep component classes lean and efficient.
You must register at least one provider of any service you are going to use. A service can be provided for specific modules or components or it can be made available everywhere in your application.
@Injectable({
providedIn: 'root',
})
Angular creates a single, shared instance if a service is provided at root level. This shared instance is injected into any class that asks for it. By using the @Injectable() metadata, Angular can remove the service from the compiled app if it isn't used.
Registering a provider with a specific NgModule will return the same instance of a service to all components in that NgModule if they ask for it.
@NgModule({
providers: [
BackendService,
Logger
],
...
})
A new instance of a service is generated for each new instance of the component if you register the provider at component level.
@Component({
selector: 'app-hero-list',
templateUrl: './hero-list.component.html',
providers: [ HeroService ]
})
Directives add behavior to an existing DOM element or an existing component instance. The basic difference between a component and a directive is that a component has a template, whereas an attribute or structural directive does not have a template and only one component can be instantiated per an element in a template.
We can differentiate between three types of directives:
Angular provides two ways to compile your app. The compilation step is needed as Angular templates and components cannot be understood by the browser therefore the HTML and TypeScript code is converted into efficient JavaScript code.
When you run the ng serve or ng build CLI commands, the type of compilation (JIT or AOT) depends on the value of the aot property in your build configuration specified in angular.json. By default, aot is set to true for new CLI apps.
JIT compiles your app in the browser at runtime. This was the default until Angular 8.
AOT compiles your app at build time. This is the default since Angular 9.
By default, NgModules are eagerly loaded, which means that as soon as the app loads, so do all the NgModules, whether or not they are immediately necessary. For large apps with lots of routes, consider lazy loading—a design pattern that loads NgModules as needed. Lazy loading helps keep initial bundle sizes smaller, which in turn helps decrease load times.
After your application instantiates a component or directive by calling its constructor, Angular calls the hook methods you have implemented at the appropriate point in the lifecycle of that instance.

Angular calls these hook methods in the following order:
ViewChild and ContentChild are used for component communication in Angular, for example, if a parent component wants access to one or multiple child components.
In Angular exist two different DOMs:
<ng-content>.Both types of modules can help to modularize code and Angular relies on both kinds of modules but they are very different.
A JavaScript module is an individual file with JavaScript code, usually containing a class or a library of functions for a specific purpose within your app.
NgModules are specific to Angular and a NgModule is a class marked by the @NgModule decorator with a metadata object.
@HostListener() function decorator allows you to handle events of the host element in the directive class. For example, it can be used to change the color of the host element if you hover over the host element with the mouse.@HostBinding() function decorator allows you to set the properties of the host element from the directive class. In this directive class, we can change any style property like height, width, color, margin, border, etc.Please read my article The Last Guide For Angular Change Detection You'll Ever Need for a detailed explanation. 
Component CSS styles are encapsulated into the component's view to avoid styling side effects in the rest of the Angular application.
The type of encapsulation can be controlled per component via the encapsulation property in the component metadata:
// warning: few browsers support shadow DOM encapsulation at this time
encapsulation: ViewEncapsulation.ShadowDom
You can choose between the following modes:
ViewEncapsulation.Emulated which is the default mode and emulates the shadow DOM behavior. It renames and preprocesses the CSS code to effectively scope the CSS to the component's view. Each DOM element gets attached some additional attributes like _nghost or _ngcontent. An element that would be a shadow DOM host in native encapsulation has a generated _nghost attribute. This is typically the case for component host elements. An element within a component's view has a _ngcontent attribute that identifies to which host's emulated shadow DOM this element belongs.ViewEncapsulation.None which tells Angular to not use view encapsulation and adds CSS to the global styles. Essentially, this is the same behavior as pasing the component's styles into the HTML.ViewEncapsulation.ShadowDom which uses the browser's native shadow DOM implementation. It attaches a shadow DOM to the component's host element and then puts the component view inside that shadow DOM. The component's styles are included within the shadow DOM.I hope this list of Angular interview questions will help you to get your next Angular position. Leave me a comment if you know any other important Angular interview questions.
