About angular custom directive

Source: Internet
Author: User

A summary of angular custom directive

First we create a custom directive directive named "Expander":

Angular.module ("myApp", []). Directive ("expander",function() {    return{ //directive's Some properties (key-value pairs form) are as follows:
/*
Restrict: ' EA ',
Replace:true,
Transclude:true,
scope:{...},
Template: .....,
Templateurl: .....,
Link:function (scope,element,attrs) {
      
}
*/
}
});

There are several main properties:

    1. restrict
      E: Indicates that this directive can only be used in element mode, i.e.:<my-dialog></my-dialog>
      A: It means that it directive can only be used in attribute mode, i.e.:<div my-dialog></div>
      EA: Indicates that it can be used in directive either element or attribute mode

    2. transclude
      is embedded, true/false.

    3. scope
      When you write this property, it means that it will directive not inherit from it controller $scope , but will recreate it.
    4. Tempalte
      Replace the real HTML code of the custom directive
    5. templateUrl
      To replace a template path for a custom directive
    6. link
      It can be simply understood that when directive compiled by angular, the method is executed

linkThe first parameter scope is basically the one you said above scope .

elementIn short, it is$(‘expander‘)

attrsis a map that contains all of the attributes you have on this directive page, for example: if you write on the pages directive :

<expander type="modal" animation="fade"></expander>

That attrs is:
{
Type: ' Modal ',
Animation: ' Fade '
}

About angular custom directive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.