Exploring Attribute Directives in Angular

Attribute Directives are used to change the behavior, appearance or look of an element on a user input or via data from the service. Essentially, there are three types of directives in Angular:

  1. Component
  2. Structural directives
  3. Attribute directives

image

In this post, we will learn how to create Attribute Directives in Angular . So let’s say we want to change the background color of an element; in that case we would apply the attribute directive to the element.

Create first Attribute directive

Let’s start with creating the Attribute Directive. To do this, we need to create a class and decorate it with @directive decorators. A simple attribute directive to change the color of an element can be created as shown in the next listing:

Read full post on Infragistics blog

 


Discover more from Dhananjay Kumar

Subscribe to get the latest posts sent to your email.

Published by Dhananjay Kumar

Dhananjay Kumar is founder of NomadCoder and ng-India

2 thoughts on “Exploring Attribute Directives in Angular

  1. hi, in angularJs, we can pass function in directive as attribute and call it from directive… how to do this in angular? how to do DIrective and component communication in angular?

Leave a comment

Discover more from Dhananjay Kumar

Subscribe now to keep reading and get access to the full archive.

Continue reading