title: AngularJS: directives vs. controllers - What logic to put where?
body: <p>I'm quite new to angular and try to really learn how to organize my code, so future coworkers will be able to find their way around it quickly.</p>
  
  <p>One rule I know is "If it manipulates the DOM, put it into a directive", which I abide by.</p>
  
  <p>But still there are times where I am unsure where to put my methods, as I can put them into the main app controller, into a controller supplied as the "controller" option within the directive or even within the function that inits the directive (option "link").</p>
  
  <p>With filters and services it's pretty clear to me, but with controllers and directives the line becomes pretty blurry.
  I already realized that even with a little app I spread some of the code here and there and it's already confusing, even to myself. So I'd like to get some Tipps on organizing my code better.</p>
  
  <p>So I guess my main question is:<br>
  1) Is there a good rule of thumb to know what code to put where?</p>
  
  <p>Or if this is too abstract here are some examples:<br>
  2) I have a directive with a template which I only use within my app. Something should happen, when I click on the element. I already know its preferable to use the ng-click directive over binding a click event within the linked function.<br>
  But where should I define the method supplied in ng-click?</p>
  
  <ul>
  <li>A) The main controller of the app.</li>
  <li>B) The "link" function of the directive.</li>
  <li>C) Add a controller to the directive (using the "controller" option) and define it there.</li>
  </ul>
  
  <p>3) Would the answer to 2) be different if I plan to reuse the directive elsewhere?</p>
  
  <p>4) Different Scenario:<br>
  I have a Button and when clicked and dragged it should move a completely unrelated Element.<br>
  Should I...</p>
  
  <ul>
  <li>A) Create one directive and influence template &amp; behavior based on a passed attribute?</li>
  <li>B) Create two directives (one for the handle, one for the target Element)<br>
  If so, it again poses the question of where to put the methods to handle the dragging?</li>
  </ul>
  
  <p>Notes:<br>
  I am aware the answers might be a little dependent on personal opinion, but I kinda hope there are some "rules" or "right ways to do it" to which I can abide by for future development.
  I didn't include any code for conciseness reasons.
  Should it be needed for an answer I'd be happy to provide it.</p>
  
  <p>thank you for your time.</p>