Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Expressions and Directives not parsed. "Cannot read property 'childNodes' of undefined" #8137

Closed
QueueHammer opened this issue Jul 10, 2014 · 5 comments

Comments

@QueueHammer
Copy link

I'm getting an error in what looks to be the compile step where the node is undefined when calling childLinkFn inside compositeLinkFn. This was causing some expression and directives to not be evaluated in the document. Changing } else if (childLinkFn) { to } else if (childLinkFn && node) { works but I want to know more about the issue. The base module, "app", is bound to body and it contains a good ammount of SVG elements though I did not find that they were apart of the issue. Also, the page is rather small in that it has less than 5000 DOM elements in it. Is this related to another bug, or is there some other issue I can look for to fix the issue besides the patch I made?

line:6040 of angular.js (1.2.19)

} else if (childLinkFn) {
  childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn);
}

Error Dump

TypeError: Cannot read property 'childNodes' of undefined
    at compositeLinkFn (.../angular.js:6042:36)
    at compositeLinkFn (.../angular.js:6042:13)
    at compositeLinkFn (.../angular.js:6042:13)
    at compositeLinkFn (.../angular.js:6042:13)
    at compositeLinkFn (.../angular.js:6042:13)
    at compositeLinkFn (.../angular.js:6042:13)
    at compositeLinkFn (.../angular.js:6042:13)
    at publicLinkFn (.../angular.js:5934:30)
    at .../angular.js:1420:27
    at Scope.$eval (.../angular.js:12595:28) 
@Narretz
Copy link
Contributor

Narretz commented Jul 10, 2014

Can you please provide a plunker or similar which reproduces the problem?

@QueueHammer
Copy link
Author

I could create a bin / plunker / fiddle that produces the the same error text. Would it be produced by the same cause, I would not be cretin. Can you suggest a way for me to debug to find out more information?

@Narretz
Copy link
Contributor

Narretz commented Jul 11, 2014

If you know in what function / line the error is thrown, you can add a break point in it, and try to extract some data from it, such as the directive name, element etc. Then try to remove some elements, directives etc. or try some elements in isolation, and see if the error persists.

@Narretz
Copy link
Contributor

Narretz commented Sep 7, 2014

Closing this for now, feel free to reopen with more information. Thanks!

@Narretz Narretz closed this as completed Sep 7, 2014
@bertyhell
Copy link
Contributor

I had a similar issue. I'll just put my solution here for anyone that has the same issue.

The cause: Modifying the dom while it's being compiled.

I was adding a lot of html to the dom and then using $compile to compile it.
Inside the html the was a directive that would then change it's dom structure using jQuery.

The solution: Use $timeout.

To avoid the "Cannot read property 'childNodes' of undefined" you just have the wrap the jQuery code that modifies the DOM inside a $timeout function with delay set to 0. I'm thinking this avoids the code to run while angular is still compiling the code.

The code:

this.$timeout(function() {
  this.element.children().wrapAll('<div class="wrapper-element"></div>');
}, 0);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants