Extend the DOM with custom elements and attributes
Powerful, but complex
myModule.directive('directiveName', function factory(injectables) {
var directiveDefinitionObject = {
priority: 0,
template: '<div></div>',
transclude: false,
restrict: 'A',
templateNamespace: 'html',
scope: false,
controller: function($scope, $element, $attrs, $transclude, otherInjectables) { ... },
controllerAs: 'stringIdentifier',
bindToController: false,
require: 'siblingDirectiveName',
compile: function compile(tElement, tAttrs, transclude) {
return {
pre: function preLink(scope, iElement, iAttrs, controller) { ... },
post: function postLink(scope, iElement, iAttrs, controller) { ... }
};
},
};
return directiveDefinitionObject;
});
Components are the main primitive from which user interfaces are built.
Attribute directives attach behavior to elements.
Added in 1.5 to make the transition to Angular 2 easier.
Syntactic sugar for creating component directives.
directive
for things
that modify an existing DOM element.
controllerAs
to $ctrl
bindToController: true
)