AngularJS provides support for creating custom directives for the following type of elements:
- Element Directive
Element directives are activated when a matching element is encountered. - Attribute
Attribute directives are activated when a matching attribute is encountered. - CSS
CSS directives are activated when a matching CSS style is encountered. - Comment
Comment directives are activated when a matching comment is encountered. - In AngularJS, directives are markers on a DOM element that tell AngularJS’s HTML compiler ($compile) to attach a specified behavior to that DOM element or transform the DOM element and its children. There are several types of directives in AngularJS:
- Attribute Directives:
- These modify the appearance or behavior of an element.
- Examples include ng-model, ng-show, ng-hide, ng-src, etc.
- Element Directives:
- These are used as new HTML elements.
- Examples include ng-view, ng-form, ng-app, etc.
- Class Directives:
- These are used to conditionally apply CSS classes to elements.
- Example includes ng-class.
- Comment Directives:
- These are directives specified as comments.
- Example includes ng-repeat.
- Multi-element Directives:
- These are directives that can be applied to multiple elements.
- Example includes ng-repeat.
- Structural Directives:
- These deal with the DOM structure.
- Examples include ng-if, ng-switch, ng-repeat.
- Transclusion Directives:
- These are used to copy or clone DOM elements.
- Example includes ng-transclude.
- Animation Directives:
- These are used for adding animations to elements.
- Examples include ng-animate.
These directives allow developers to extend the functionality of HTML in a declarative manner. Each type serves a specific purpose, and developers can create custom directives as well to encapsulate and reuse functionality within their AngularJS applications. Keep in mind that AngularJS is an older version of Angular, and Angular (versions 2 and above) uses a different approach to directives
- Attribute Directives: