Which directive is used in Angular to conditionally display an element in the DOM?

  • *ngClass
  • *ngFor
  • *ngIf
  • *ngSwitch
In Angular, the *ngIf directive is used to conditionally display an element in the DOM. It evaluates an expression and only renders the associated element if the expression is true. This is commonly used for showing or hiding elements based on certain conditions. *ngFor is used for looping over arrays and rendering lists, not for conditional rendering. *ngSwitch is used for switching between multiple views based on a condition, and *ngClass is used for dynamically adding or removing CSS classes.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *