Angular Interview Questions – Set 02

What is AngularJS Expression?

AngularJS expressions are written inside double braces {{ expressions }} or inside a directive: ng-bind=”expression”. AngularJS expressions are like JavaScript expressions which can contain literals, operators, and variables.

What is Angular?

Angular is a TypeScript-based open-source web application framework developed and maintained by Google. It is written in TypeScript language. Angular provide a simple, easy and powerful way to create a reactive single page applications. It is a complete rewrite of AngularJS.

What is interpolation in Angular?

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

What are components in Angular?

Components are the key features of Angular. They are the main building blocks of an Angular application. Angular components make your complex application into reusable parts which you can reuse very easily.

You can easily create components by using Angular CLI.

Syntax:

ng generate component component_name
Or
ng g c component_name

What is Data binding in Angular?

In Angular, data binding is an automatic synchronization of data between the model and view components. Two-way data binding is very popular and powerful feature of Angular which creates a bridge between the view and the business logic of the Angular apps.

What is main differences between Angular expression and JavaScript expression?

Angular expressions are like JavaScript expressions but there is a difference between them as Angular expressions are evaluated against a scope object while JavaScript expressions are evaluated against a global window object.

What is the different versions of Angular?

AngularJS was the first version of Angular which was also known as Angular 1. It was released on October 20, 2010. After that version, Google developed a newer version of AngularJS which was a complete rewrite of the previous one. That was known as Angular 2. After that Angular 4, Angular 6, Angular 7 and Angular 8 are released. Angular 8 is its current version.

Angular versions:

  • AngularJS
  • Angular 2
  • Angular 4
  • Angular 6
  • Angular 7
  • Angular 8

What are template expressions in Angular?

A template expression gives a value similar to any JavaScript expression. Angular executes the expression and assigns it to a property of a binding target. The target might be an HTML element, a component, or a directive. In the property binding, a template expression appears in quotes to the right of the = symbol as in [property]=”expression”. In interpolation syntax, the template expression is surrounded by double curly braces. For example, in the below interpolation, the template expression is {{username}},

{{username}}, welcome to Angular

The below JavaScript expressions are prohibited in template expression.

assignments (=, +=, -=, …)
new
chaining expressions with ; or ,
increment and decrement operators (++ and –)

What is Angular CLI?

Angular CLI is a Command Line Interface for Angular. It facilitates you to create an application and different components.

Install Angular CLI:

To install the latest version of Angular CLI, run the following npm command.

npm install @angular/cli@latest
To create an application:

The ng new command is used to create a new application in Angular.

Syntax:

ng new application_name
To create components routes, services and pipes:

The ng generate command is used to create a new component, routes, services and pipes in the application.

Syntax:

ng new component_name
To test your app running locally:

The ng serve command is used to test your app locally while developing.

Syntax:

ng serve

What is a service in Angular?

In Angular, services are used to provide a common functionality to various modules. A service provides better modularity for your app by allowing you to extract common functionality out of components.

Let’s see how to create a service which can be used across multiple components. Here, service name is EgService.