Angular Interview Questions – Set 01

What is metadata in Angular?

In Angular, component and services are simply classes with decorators that mark their type and provide metadata that tells Angular how to use them. So, metadata is used to decorate a class to configure the expected behavior of the class.

What is dependency injection (DI) in Angular?

Dependency injection (DI) is an important application design pattern. In DI, a class asks for dependencies from external sources rather than creating them itself. Angular has its own dependency injection framework to resolve dependencies. So, your services depend on other services throughout your application.

What is compilation in Angular? What types of compilations are used in Angular?

The Angular applications are written in TypeScript and HTML. Their components and templates must be converted to executable JavaScript by the Angular compiler. There are two types of compilations in Angular:

Just-in-time (JIT) compilation: This is a standard development approach which compiles our Typescript and html files in the browser at runtime, as the application loads. It is great but has disadvantages. Views take longer to render because of the in-browser compilation step. App size increases as it contains angular compiler and other library code that won’t actually need.

Ahead-of-time (AOT) compilation: With AOT, the compiler runs at the build time and the browser downloads only the pre compiled version of the application. The browser loads executable code so it can render the application immediately, without waiting to compile the app first. This compilation is better than JIT because of fast rendering, smaller application size, security and detect template errors earlier.

What is AngularJS?

AngularJS is a JavaScript framework which is added to the HTML with tag. It is written in JavaScript. It is used to extend HTML attributes with Directives, and binds data to HTML with Expressions. Angular JS was first released on October 20, 2010 by Google and licensed under MIT.

What is the use of ngFor directive in Angular?

Angular ngFor directive is used in a template to display each item in a list. For example, here we iterate over list of users,

  • {{ user }}

The user variable in the ngFor double-quoted instruction is a template input variable.

What are directives in Angular?

In Angular, a directive is a function which is executed when the Angular compiler finds it in the Angular DOM. Directives specify how to control components and business logic in Angular applications.

There are mainly three type of directives:

  • Component Directives
  • Structural Directives
  • Attribute Directives

What is the difference between Angular and React?

Angular and React both are related to JavaScript but there are a lot of differences between them. See the main differences between Angular and React:

  • Angular is a JavaScript framework while React is a JavaScript library.
  • Angular is written in TypeScript while React is written in JavaScript.
  • Angular is developed and maintained by Google while React is developed and maintained by Facebook.
  • The first version of Angular was AngularJS and released in 2010 while the first version of React was released in 2013.
  • Angular is a full MVC (Model, View, and Controller) framework while React is a simple JavaScript library. It is just the View model.
  • Angular uses regular DOM which updates the entire tree structure of HTML tags that’s why is is comparatively slow than
  • Angular while React uses virtual DOM which makes it amazing fast. It is the most prominent feature of React.
  • Angular provides two-way data binding while React provide one-way data binding.
  • Angular is easy to scale while React is more scalable than Angular.
  • Angular is fast as compared to old technologies but React is faster than Angular.

What are the most important features of AngularJS?

The most important features of AngularJS are:

  • Model
  • View
  • Controller
  • Directives
  • Scope
  • Services
  • Data Binding
  • Filters
  • Testable

What is the use of ngIf directive?

Angular ngIf directive is used when you want to display a view or a portion of a view only under specific circumstances. The Angular ngIf directive is used to insert or remove an element according to the true/false condition.

What is ng-content directive in Angular?

The ng-content directive is a feature of Angular which helps us to make reusable components.

For example: In conventional HTML, tags are used to write something. i.e.

This is a paragraph

. Now, see the following example of having custom text between angular tags:

This won’t work like HTML until you use ng-content Directive

This will not work same as HTML element. To make it work just like the above HTML example, we need to use the ng-content directive.