Directive Definition Object
Each directive defines the factory function, which needs to return a directive definition object, which the compiler/$compile expands upon at compile time according to the definition object.
The common properties of the directive definition object are as follows:
The link function is responsible for implementing data binding for the DOM and scope, typically performing DOM event monitoring and data change monitoring in link. The link function is called after the template executes. Link is the most commonly used attribute, and the logic of an instruction is usually implemented in the link function.
The link function is in the following form:
- function link(scope,ielement,iattrs,controller,transcludefn ){...}
This can be any combination of the four letters of the EACM, used to limit the application of the instruction. If you do not specify this property, by default, directives are only allowed to be used as element and attribute names:
- * E - element name, e.g.:<my-directive></My-directive>
- * A - attribute name, for example:<div my-directive="exp"></Div >
- * C - class, for example:<div class="MY-DIRECTIVE:EXP;" ></div>
- * M - note, e.g.:<!-- directive:My-directive exp --and
The template is an HTML fragment that can be used to:
- * Replace the contents of the instruction. This is the default behavior and can be changed using the Replace property.
- * Replace the instruction itself ( if the Replace property is set to TRUE ).
- * the contents of the package instruction (if the transclue property is set to TRUE ).
Indicates whether to replace the instruction element with a template.
- * true - when compiling, a template is used to replace the instruction element
- * false - when compiling, the contents of the instruction element will be replaced with the template
Directive definition Object--advanced stage