AngularJS Directives

AngularJS Directives are markers on a DOM that tell the compiler of AngularJs to attach a specific behavior to that DOM element. AngularJS helps to extend HTML, using directives. AngularJS has some built in directives and it also lets us define our own directives. Basically, AngularJs directive is the extended HTML with prefix ng.
Some built in AngularJS Directives are given below.
  • ng-app- This initializes the AngularJS Application. It defines the root of Angular Application.
  • ng-init- This initializes the application's data.
  • ng-model- This directive binds the values of AngularJS application data to HTML input controls.
  • ng-bind- This directive binds the application data to View (HTML View).
 
After reading this, we must have a question in our mind about what the HTML compiler is. What does it mean to compile HTML? In AngularJS, compilation means attaching the directives to HTML elements to make them attractive in order to transform the elements.
Some AngularJS defined directives are given below.

DirectiveDescription
ng-appDefines the root element of an application.
ng-bindBinds the content of an HTML element to application data.
ng-bind-htmlBinds the innerHTML of an HTML element to Application data and also removes dangerous code from the HTML string.
ng-bind-templateSpecifies that the text content should be replaced with a template.
ng-blurSpecifies a behavior on blur events.
ng-changeSpecifies an expression to evaluate when the content is being changed by the user.
ng-checkedSpecifies if an element is checked or not.
ng-classSpecifies CSS classes on HTML elements.
ng-class-evenSame as ng-class, but will only take effect on even rows.
ng-class-oddSame as ng-class, but will only take effect on odd rows.
ng-clickSpecifies an expression to evaluate when an element is being clicked.
ng-controllerDefines the controller object for an application.
ng-copySpecifies a behavior on copy events.
ng-cutSpecifies a behavior on cut events.
ng-dblclickSpecifies a behavior on double-click events.
ng-disabledSpecifies if an element is disabled or not.
ng-focusSpecifies a behavior on focus events.
ng-formSpecifies an HTML form to inherit the controls from.
ng-hideHides or shows HTML elements.
ng-hrefSpecifies a URL for the <a> element.
ng-ifRemoves HTML element, if a condition is false.
ng-includeIncludes HTML in an application.
ng-initDefines initial values for an application.
ng-jqSpecifies that the application must use a library, like jQuery.
ng-keydownSpecifies a behavior on keydown events.
ng-keypressSpecifies a behavior on keypress events.
ng-keyupSpecifies a behavior on keyup events.
ng-listConverts text into a list (array).
ng-maxlengthSpecifies the maximum number of characters allowed in the input field.
ng-minlengthSpecifies the minimum number of characters allowed in the input field.
ng-modelBinds the value of HTML controls to the application's data.
ng-model-optionsSpecifies how updates in the model are done.
ng-mousedownSpecifies a behavior on mousedown events.
ng-mouseenterSpecifies a behavior on mouseenter events.
ng-mouseleaveSpecifies a behavior on mouseleave events.
ng-mousemoveSpecifies a behavior on mousemove events.
ng-mouseoverSpecifies a behavior on mouseover events.
ng-mouseupSpecifies a behavior on mouseup events.
ng-non-bindableSpecifies that no data binding can happen in this element, or its children.
ng-openSpecifies the open attribute of an element.
ng-optionsSpecifies <options> in a <select> list.
ng-pasteSpecifies a behavior on paste events.
ng-pluralizeSpecifies a message to display according to en-us localization rules.
ng-readonlySpecifies the readonly attribute of an element.
ng-repeatDefines a template for each data in a collection.
ng-requiredSpecifies the required attribute of an element.
ng-selectedSpecifies the selected attribute of an element.
ng-showShows or hides HTML elements.
ng-srcSpecifies the src attribute for the <img> element.
ng-styleSpecifies the style attribute for an element.
ng-submitSpecifies expressions to run on onsubmit events.
ng-switchSpecifies a condition that will be used to show/hide child elements.
ng-valueSpecifies the value of an input element.

Example of a directive:

Paste your text here<div ng-app="">

    <p>FirstName: <input type="text" ng-model="fname"></p>

    <p ng-bind="fname"></p>

</div>
ng-app directive is used in the div tag <div>. This makes this div tag the owner of this AngularJS application, which means this confirms that from this div, we are staring the Angular application and Angular features will be starting from this tag.
ng-model directive, in the input tag, binds the value of this input field to variable “fname.”This fname's value has been assigned by this ng-model. Whatever we type in this input field, the value will be assigned to fname variable. ng-bind directive now binds the value, which was assigned to the variable “fname”, to innerHtml of the <span> tag.

Reference:
Overview Of AngularJS Directives 
AngularJS Directives AngularJS Directives Reviewed by Bloggeur DZ on 08:01 Rating: 5

3 commentaires:

  1. I am very grateful to read your blog.I hope you would provide the great services in the field of Angularjs development.
    hire AngularJS developer

    RépondreSupprimer
  2. Looking to Hire Wordpress Developer in India ? Hire wordpress developer from indian web developers. We are leading hire wordpress developer company provides custom wordpress developer services in India.

    RépondreSupprimer

Fourni par Blogger.