My main question is simple :
I get errors when doing DOM manipulation within Controllers or Directives however, the functionality works perfectly.
Erro
Although the accepted answer is right I'd like to share my experience anyway as it turned out to be a different problem. In fact I had the same issue but I wasn't actually returning anything at all from my function (and not using CoffeeScript) so i was puzzled for a bit and struggled to find a solution.
In my case the problem appeared to be that I was passing the DOM node as an argument to the function like so:
What proved to be a solution here was changing the mentioned code to pass only the event and not the node directly:
Then fetch the node in the controller/directive/whatever like so:
doSomething = function(evt){
var elem = evt.currentTarget;
// do something with this element...
};