Introducing Directives
Learn what Angular directives are and how to use the ngIf directive in templates.
Angular directives are HTML attributes that extend the behavior or the appearance of a standard HTML element. When we apply a directive to an HTML element or even an Angular component, we can add custom behavior to it or alter its appearance. There are three types of directives:
Components: They are directives with an associated template.
Structural directives: They add or remove elements from the DOM.
Attribute directives: They modify the appearance of or define a custom behavior for a DOM element.
Angular provides us with a set of built-in directives that we can use in our components to cover most use cases. Angular built-in directives are part of the CommonModule
. So, we need to import CommonModule
when we want to use them.
Note: The Angular CLI imports
CommonModule
by default when we create a new Angular module, as we learned previously. ...