Top 10 Angular 8/9 Interview Questions and Answers to Know in 2020

Q1:- difference between Promise and Observable in Angular?

Ans: - Promises:
 return a single value
 not cancellable
 more readable code with try/catch and async/await
Observables:
 work with multiple values over time
 cancellable
 support map, filter, reduce and similar operators
 use Reactive Extensions (RxJS)
 an array whose items arrive asynchronously over time

Q2:- What is AOT (Ahead-Of-Time) Compilation?

Ans: - Each Angular app gets compiled internally. The Angular compiler takes in the JS code, compiles it and then produces some JS code. This happens only once per occasion per user. It is known as AOT (Ahead-Of-Time) compilation.

Q3:- What is ngOnInit ()? How to define it?

Ans: - ngOnInit () is a lifecycle hook that is called after Angular has finished initializing all data-bound properties of a directive.

Q4:- Angular 8: Explain Lazy Loading in Angular 8?

Ans:- Lazy loading is one of the most useful concepts of Angular Routing and brings down the size of large files. This is done by lazily loading the files that are required occasionally.
Angular 8 comes up with support for dynamic imports in our router configuration. This means that we use the import statement for lazy loading the module and this will be understood by the IDEs, webpack, etc.
Angular7:

Angular 8:

New with Angular 8, loadChildren expects a function that uses the dynamic import syntax to import your lazy-loaded module only when it’s needed. As you can see, the dynamic import is promise-based and gives you access to the module, where the module’s class can be called.

Q5:-What is the code for creating a decorator?

Ans: We create a decorator called Dummy.
function Dummy(target) {
dummy.log(‘This decorator is Dummy’, target);
}

Q6: How to generate a class in Angular 7 using CLI?

Ans: ng generate class Dummy [options]

Alternative- use URL link- https://update.angular.io/

Q8:-. What are advanced Angular CLI commands?

Ans: - Some of the best Angular CLI commands that enhances developers’ productivity are

  1. ng-new – Generate new angular projects
  2. ng-generate – Generate components using the Angular CLI
  3. ng-serve – Run your app with just this command
  4. ng-eject – Pull the ripcord

Output:- highlight me!

Q10:- What are the key components of Angular?

Ans:- The key components of Angular are Components, Modules, templates, services and metadata.
Components are basic building blocks that control HTML views. Modules are the set of these building blocks like components, directives and many others. Simply put, each logical piece of code is a module. Templates represent the views of the angular application. With Metadata, you can add more data to Angular class.

#angular #angular8 #angular9

Top 10 Angular 8/9 Interview Questions and Answers to Know in 2020
30.85 GEEK