-
Notifications
You must be signed in to change notification settings - Fork 27.5k
AngularJS is throwing "TypeError: Cannot read property 'childNodes' of undefined" when using DOM elements that trigger directives in ng-view #5069
Comments
This seems to be have been introduced by this commit: b7a5449 |
The exception is being thrown on this line: https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L935 |
It seems that |
It only occurs if the content of the ng-view element contains Angular directives and that these directives are not on the top level nodes of the child contents of the ng-view element. |
I suspect that ngView used to be terminal directive but now it's not and it is somehow affecting the next compilation. I updated the test case and removed it further down to the least amount of nodes in ngView that repro the issue: <!doctype html>
<html ng-app="test">
<head>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js"></script>
<script type="text/javascript" src="http://code.angularjs.org/1.2.1/angular-route.js"></script>
<script type="text/javascript">
angular.module('test', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
template: 'Hello world!'
});
}]);
</script>
</head>
<body>
<div ng-view>myText<p><a></a></p></div>
</body>
</html> |
Here is the same error without routes and ngView with a custom directive
The crucial thing here is the do |
So we have the following situation:
The problem exists as The same can be reproduced with the following code snippet:
|
The reason why the example only fails if the html structure is so specific (text-node, outer-node with inner node that has a directive) and not for a html template like If we use a directive that accesses the underlying element directly, we get a corresponding error more easily:
So to summarize, the problem is that we change the elements in the |
…nt with directives. Related to angular#5069
…h directives. Fixes angular#5069
…nt with directives. Related to angular#5069
…h directives. Fixes angular#5069
…nt with directives. Related to angular#5069
…h directives. Fixes angular#5069
Currently getting this error thrown when trying to use the
|
@tomtom87 - can you provide a running example of this (perhaps in a plunker) and create a new issue so that we can investigate? |
Help me out from this issue |
when using ng-view this happened to me. just try to use
in the controller related to your state. |
<title></title>
<style>
.box{background:#eee;transition:2s all;position: absolute}
|
This also seems to happen when adding DOM elements by JS ahead of other DOM elements that were defined in HTML.
|
@Nokel81, it would be awesome if you could create a demo. |
https://plnkr.co/edit/Rwoduo3qe6s1WIeb1hO2 Here is a plunker that shows the error, the lines of code to add the canvas is at the bottle of the controller's function |
@Nokel81, I see. This is something different, because you are manipulating the DOM from inside a controller (which is not supported). Note that controllers are instantiated after compilation and before linking. Since linking depends on the state of the DOM during compilation it is a realy bad idea to change the DOM structure inside controllers. Typically, such manipulation should happen in the post-linking phase (when both the element and all its children have been compiled and linked). If you want to do it from a controller, you should use the BTW, |
Dear angular guys,
after upgrading AngularJS from version 1.0.8 to 1.2.1 we've encountered an exception being thrown in compositeLinkFn on line 5539:
This error seems to occur only when the routing module is in use and tags are nested within the ng-view container. At least one of these tags must also match any angularjs directive (such as a-tags or form-tags).
Reproducable: always
Browsers: Chrome 31, Firefox 25 and IE 10
Operating system: Windows 8.1
Steps to reproduce:
As soon as the <a>-Tag is removed, the exception disappears. This issue might be related to #2532.
The text was updated successfully, but these errors were encountered: