Read more

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

Dominik Schöler
March 31, 2015Software engineer at makandra GmbH

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
}
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

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.

Posted by Dominik Schöler to makandra dev (2015-03-31 15:58)