Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Angular Interview Questions and Answers

Related differences

Related differences

Angular vs ReactAngularJS vs NodeJSAngularJS vs Angular
Jquery vs AngularJS

Ques 26. 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.

Let's take an example,

<h3>

  {{title}}

  <img src="{{url}}" style="height:30px">

</h3>

In the example above, Angular evaluates the title and url properties and fills in the blanks, first displaying a bold application title and then a URL.

Is it helpful? Add Comment View Comments
 

Ques 27. What are template expressions in Angular?

A template expression produces 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}},

<h3>{{username}}, welcome to Angular</h3>

The below javascript expressions are prohibited in template expression

  1. assignments (=, +=, -=, ...)
  2. new
  3. chaining expressions with ; or ,
  4. increment and decrement operators (++ and --)

Is it helpful? Add Comment View Comments
 

Ques 28. What are template statements?

A template statement responds to an event raised by a binding target such as an element, component, or directive. The template statements appear in quotes to the right of the = symbol like (event)="statement".

Let's take an example of button click event's statement

<button (click)="editProfile()">Edit Profile</button>

In the above expression, editProfile is a template statement. The below JavaScript syntax expressions are not allowed.

  1. new
  2. increment and decrement operators, ++ and --
  3. operator assignment, such as += and -=
  4. the bitwise operators | and &
  5. the template expression operators

Is it helpful? Add Comment View Comments
 

Ques 29. How do you categorize data binding types in Angular?

Binding types can be grouped into three categories distinguished by the direction of data flow. They are listed as below,

  1. From the source-to-view
  2. From view-to-source
  3. View-to-source-to-view

The possible binding syntax can be tabularized as below,

Data directionSyntaxType
From the source-to-view(One-way)1. {{expression}} 2. [target]="expression" 3. bind-target="expression"Interpolation, Property, Attribute, Class, Style
From view-to-source(One-way)1. (target)="statement" 2. on-target="statement"Event
View-to-source-to-view(Two-way)1. [(target)]="expression" 2. bindon-target="expression"Two-way

Is it helpful? Add Comment View Comments
 

Ques 30. What are pipes in Angular?

A pipe takes in data as input and transforms it to 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.

import { Component } from '@angular/core';

@Component({

  selector: 'app-birthday',

  template: `<p>Birthday is {{ birthday | date }}</p>`

})

export class BirthdayComponent {

  birthday = new Date(1987, 6, 18); // June 18, 1987

}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook