title: Angular directives - when and how to use compile, controller, pre-link and post-link
body: <p>When writing an Angular directive, one can use any of the following functions to manipulate the DOM behaviour, contents and look of the element on which the directive is declared:</p>
  <ul>
  <li>compile</li>
  <li>controller</li>
  <li>pre-link</li>
  <li>post-link</li>
  </ul>
  <p>There seem to be some confusion as for which function should one use. This question covers:</p>
  <h2>Directive basics</h2>
  <ul>
  <li><a href="https://stackoverflow.com/a/24615123/1179377">How to declare the various functions?</a></li>
  <li><a href="https://stackoverflow.com/a/24615137/1179377">What is the difference between a <em>source template</em> and an <em>instance template</em>?</a></li>
  <li><a href="https://stackoverflow.com/a/24615162/1179377">In which order the directive functions are executed?</a></li>
  <li><a href="https://stackoverflow.com/a/24615185/1179377">What else happens between these function calls?</a></li>
  </ul>
  <h2>Function nature, do's and dont's</h2>
  <ul>
  <li><a href="https://stackoverflow.com/a/24615207/1179377">Compile</a></li>
  <li><a href="https://stackoverflow.com/a/24615239/1179377">Controller</a></li>
  <li><a href="https://stackoverflow.com/a/24615261/1179377">Pre-link</a></li>
  <li><a href="https://stackoverflow.com/a/24615104/1179377">Post-link</a></li>
  </ul>
  <h2>Related questions:</h2>
  <ul>
  <li><a href="https://stackoverflow.com/questions/15676614/">Directive: link vs compile vs controller</a>.</li>
  <li><a href="https://stackoverflow.com/questions/12546945">Difference between the 'controller', 'link' and 'compile' functions when defining an angular.js directive</a>.</li>
  <li><a href="https://stackoverflow.com/questions/12164138">What is the difference between compile and link function in angularjs</a>.</li>
  <li><a href="https://stackoverflow.com/questions/17534343">Difference between the pre-compile and post-compile element in AngularJS directives?</a>.</li>
  <li><a href="https://stackoverflow.com/questions/23770882">Angular JS Directive - Template, compile or link?</a>.</li>
  <li><a href="https://stackoverflow.com/questions/18297208">post link vs pre link in Angular js directives</a>.</li>
  </ul>