What is a directive in Angular.JS

I have instructions for determining tension in AngularJS. The definition of AngularJS itself is at best confusing:

Directives are a way to teach HTML new tricks. During DOM compilation directives are matched against the HTML and executed. This allows directives to register behavior, or transform the DOM.

Can anyone explain the directives in AngularJS in plain English, commonly used for teaching programming. Something like: directives are funcions/objects that extends ...

+6
source share
3 answers

This is a way to extend HTML, add new elements and / or add new attributes to existing elements. From Angular Developer Guide:

A directive is a DOM behavior or transformation that is triggered by the presence of a user attribute, element name, or class name. The directive allows you to expand the HTML dictionary in a declarative way.

You can use them either to add behavior to HTML by defining a link function that preserves bi-directional binding between variables belonging to regions and DOM elements, or to dynamically control the DOM by defining a compilation function that can modify or even generate new DOM elements and attributes. Consider this as a way to distribute HTML and translate it into a domain-specific language.

+9
source

Directives can be attributes, tags, or even class names.

Once you write them in your HTML markup, it will be picked up by angular and will act as you defined it.

It gives you the ability to define new custom HTML elements, for example, or new behavior attributes such as

 <div angry></div> 

And every time someone clicks on this div, he receives and warns: "I'm angry."

Basically, you can make any extension necessary to make your html as clear and understandable as possible. it all depends on how you define the directive.

+4
source

AngularJS directives are a combination of HTML template markup (i.e. attributes, elements and CSS class) and JavaScript code support. The angularJs JavaScript code defines the html data and behavior of the html element.

The AngularJs directive is used to expand the vocabulary of HTML, as they decorate html elements with new behavior and help manipulate the attributes of html elements in an interesting way.

There are some built-in directives provided by AngularJS, such as ng-app, ng-controller, ng-repeat, ng-model, etc.

0
source

All Articles