Using and creating Angular directives
Directives come in two different types: attribute directives and structural directives. Angular has a list of built-in directives and allows you to create your own directive to cover your personal use cases. Since Angular 15, a new feature was introduced: directive composition. Directive composition allows you to assign directives inside component decorators instead of their template. Directive composition can also be used to declare directives inside the decorator of other directives, resulting in a directive that applies multiple directives simultaneously.
When you want to use a directive in a standalone component, you need to add the directive to the imports
array of the component. If it’s a built-in directive, you can also import CommonModule
, as CommonModule
contains all built-in directives. When you generate a component using the built-in Nx generator, CommonModule
is added by default. This section will teach you everything about...