Directives & Pipes
Built-in directives, custom directives, attribute directives, structural directives, built-in pipes, custom pipes, pure vs impure pipes
1What is a structural directive in Angular?
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.
2What is the correct syntax for using ngFor with trackBy?
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.
3Why use trackBy with ngFor?
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.
Which directive should be used to conditionally display an element based on a condition?
What is the difference between *ngIf and [hidden]?
+19 interview questions
Other Angular interview topics
TypeScript Basics
TypeScript Advanced
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
HttpClient & API Calls
Basic State Management
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Performance Optimization
Security & Best Practices
Advanced RxJS Patterns
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free