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:
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
transclude
is embedded, true/false.
scope
When you write this property, it means that it will directive
not inherit from it controller
$scope
, but will recreate it.
- Tempalte
Replace the real HTML code of the custom directive
templateUrl
To replace a template path for a custom directive
link
It can be simply understood that when directive
compiled by angular, the method is executed
link
The first parameter scope
is basically the one you said above scope
.
element
In short, it is$(‘expander‘)
attrs
is 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