angular · Angular Basics
Which directive modifies DOM hierarchy?
Answers
- Structural directive
- Attribute directive
Welcome back, user!
```
In this case, the message "Welcome back, user!" will only be included in the DOM if `isLoggedIn` is `true`. Thus, `*ngIf` modifies the DOM hierarchy based on a condition.
## Best Practices and Insights
When using structural directives, it is important to note that Angular does not simply hide elements from the DOM - it actually adds and removes them. It means that any components inside these elements will be destroyed and reinitialized which may affect the performance if not used thoughtfully.
It is also important to remember that you can create your own custom structural directives if the built-in ones do not serve your needs. However, as the involvement of DOM manipulation can have performance implications, consider carefully before creating custom ones.
In conclusion, structural directives stand as a powerful tool in Angular's arsenal, offering dynamic and responsive design capabilities by modifying the DOM hierarchy. They present more than just cosmetic changes - they can structurally change the interface and the user's interaction with it.