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.
Loading...
Related Quiz
- How do you create a link in your template that navigates to a different route in Angular?
- How can you prevent a particular component from being checked during the entire change detection cycle?
- You are building an e-commerce application. On the product page, you want to have tabs for "Details", "Reviews", and "Related Products", each being a separate route. How would you structure this in Angular?
- In an e-commerce application, you want to ensure that product details fetched from the server are not requested again for a certain period. Which technique would be effective for this scenario?
- Which change detection strategy checks the component only when its input properties change?