Angular

Directives & Pipes

Built-in directives, custom directives, attribute directives, structural directives, built-in pipes, custom pipes, pure vs impure pipes

22 interview questionsยท
Mid-Level
1

What is a structural directive in Angular?

Answer

Structural directives modify the DOM structure by adding, removing, or manipulating elements. They are prefixed with * (e.g., *ngIf, *ngFor). Unlike attribute directives that modify appearance or behavior, structural directives can add or remove elements from the DOM.

2

What is the correct syntax for using ngFor with trackBy?

Answer

The correct syntax uses a semicolon to separate the iteration from the trackBy function. The trackBy function improves performance by allowing Angular to identify which items have changed, been added, or removed. It takes two parameters (index and item) and returns a unique identifier.

3

Why use trackBy with ngFor?

Answer

trackBy improves list rendering performance by allowing Angular to precisely identify which items have changed. Without trackBy, Angular recreates all DOM elements when changes occur. With trackBy, only modified items are updated, avoiding unnecessary recreations.

4

Which directive should be used to conditionally display an element based on a condition?

5

What is the difference between *ngIf and [hidden]?

+19 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free