Directives are the central coding idea in Angular and the source of most of its power. They are an implementation of "Domain Specific Languages," which means that you, the programmer, get to make up your own language.
Although other comments here have focused on the HTML or the Javascript which defines the directive, neither of those is really the most important concept. The big takeaway is that writing a directive in your HTML results in both HTML and Javascript code (and likely Angular code, too) getting run. At the time a directive is defined, a template is indicated which tells which HTML will actually be output in place of the directive you wrote. But more importantly, a controller is also indicated which tells which code will be available for your HTML to access, including objects and functions.
ungallery.directive('footer', function() { return { restrict: "E", controller: "footer", controllerAs: "footerController", templateUrl: 'directives/footer.html' } });
If this directive definition exists in my index.html (or any script loaded by it), then I can later write:
<footer></footer>
Into that index.html and have access to two things: the template that lives at "directives/footer.html" and a controller named "footer". Here's the definition of footerController. It exists only to give the HTML page visibility to the version number of the app, which I want to display in the footer of all pages:
var footerController = function() { this.version = CONSTANT.version; }; ungallery.controller("footer", footerController);
The controller can assign any objects or functions to the object called this and those objects and functions will be available to the template HTML because of this directive wiring. This controller assigns one value to this, this.version, so that I can get to that value from my template.
In the directive's definition, the controllerAs syntax sets the name that I use to access the controller's this from the template. The reason that controllerAs syntax and separate names are used instead of just writing {{this.something}} is to prevent confusion when a page has several directives, each with its own meaning for this. In the definition of the footer controller, this is accessed with the prefix footerController. Here's what this looks like in the template HTML when I want to display the actual version number.
<span>Version {{footerController.version}}.</span>
Hope that helps! Let me know if I need to expand upon or clarify any of this.
-- D