0% found this document useful (0 votes)
35 views4 pages

Attribute Directives: Jogesh K. Muppala

Directives in Angular give instructions to Angular on how to render templates to the DOM. There are three types of directives: structural directives that alter layout, component directives that have a template and metadata, and attribute directives that listen to and modify the behavior of other elements. Built-in attribute directives include NgStyle, NgModel, and NgClass, while custom directives can also be created.

Uploaded by

vikram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Attribute Directives: Jogesh K. Muppala

Directives in Angular give instructions to Angular on how to render templates to the DOM. There are three types of directives: structural directives that alter layout, component directives that have a template and metadata, and attribute directives that listen to and modify the behavior of other elements. Built-in attribute directives include NgStyle, NgModel, and NgClass, while custom directives can also be created.

Uploaded by

vikram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Attribute

Directives

Jogesh K. Muppala
Directives
• Angular templates are dynamic
• Directives give instructions to Angular on how to render the
templates to the DOM
• A directive can be defined in Angular as a class with the @Directive
decorator
• A component is a special kind of directive with a template
associated to it
• Two other kinds of directives in Angular: Structural and Attribute

2
Attribute Directives
• Used as attributes for elements in the template
• Listen to and modify the behavior of other HTML
elements, attributes, properties, and components
• Built-in attribute directives: NgStyle, NgModel, NgClass
• Some of the other Angular modules like the
FormsModule and RouterModule define their own
attribute directives

3
Custom Directives
• Can create our own custom directives
• Directive imported from @angular/core
– @Directive decorator
• ElementRef also imported from @angular/core
– Injected into the directive’s constructor so that the
code can access the DOM element

You might also like