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

Posted . Visible to the public.

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
Last edit
Deleted user #20
License
Source code in this card is licensed under the MIT License.
Posted by Dominik Schöler to makandra dev (2015-03-31 13:58)