Angular: Fixing "Referencing DOM nodes in Angular expressions is disallowed"

Reason

If you are using Coffeescript, it is likely to be the culprit. Since Coffeescript always returns the value of the last expression, it may return DOM nodes:

# coffeescript
scope.focus = ->
  element.focus()

# javascript
scope.focus = function() {
  return element.focus(); // wheee
}

If you e.g. use this function like this, the error will be raised:

<span ng-click="focus()">...</span>

Solution Show archive.org snapshot

By adding an explicit return value (e.g. return false), you can Coffeescript from returning a DOM node into Angular.

Dominik Schöler