‘controller as’ syntax. Directive must dene an
isolated scope if this option is used. If using a string
for the controller attribute, ‘controller as’ can be
used.
restrict
Restricts the directive to a specic directive DOM
declaration style. If omitted, the default (attributes
only) is used.
⊲ E - Element name: <my-directive></my-
directive>
⊲ A - Attribute (default): <div my-
directive=”exp”></div>
⊲ C - Class: <div class=”my-directive:
exp;”></div>
⊲ M - Comment: <!-- directive: my-
directive exp -->
type
String representing the document type used by the
markup. This is useful for templates where the root
node is non-HTML content (such as SVG or MathML).
The default value is “html”.
⊲ html - All root template nodes are HTML, and
don’t need to be wrapped. Root nodes may
also be top-level elements such as <svg> or
<math>.
⊲ svg - The template contains only SVG content,
and must be wrapped in an <svg> node prior
to processing.
⊲ math - The template contains only MathML
content, and must be wrapped in an <math>
node prior to processing.
If no type is specied, then the type is considered to
be html.
template
replace the current element with the contents of the
HTML string. Migrates classes/attributes from the
replaced element.
You can specify template as a string representing
the template or as a function which takes two
arguments tElement and tAttrs (described in
the compile function api below) and returns a string
value representing the template.
Consider using templateUrl instead of HTML
strings in your javascript.
templateUrl
Same as template but the template is loaded from
the specied URL. Because the template loading is
require
Require another directive and inject its controller as
the fourth argument to the linking function. Takes a
string name (or array of strings) of the directive(s) to
pass in. If an array is used, the injected argument will
be an array in corresponding order.
The name can be prexed with:
⊲ (no prex) - Locate the required controller on the
current element. Throw an error if not found.
⊲ ? - Attempt to locate the required controller
or pass null to the link fn if not found. Makes it
optional
⊲ ^ - Locate the required controller by searching
the element’s parents. Throw an error if not
found.
⊲ ?^ - Attempt to locate the required controller by
searching the element’s parents or pass null to
the link fn if not found.
controllerAs
If using a controller function, you can use the
myModule.directive(‘directiveName’,
function ( ) {
return {
require: ‘otherDirectiveWithCtrl’,
link: function(scope, el, attrs, ctrl) {
...
}};
} );
myModule.directive(‘directiveName’,
function ( ) {
return {
template: ‘<div>DOM in code!</div>’
};
} );