-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngRepeat breaks when re-created by ngIf under certain circumstances #14626
Comments
You briefly said there's a difference betwenn .4 and 1.5? Could you please what the last working version is? |
It works in 1.4.10 (https://jsfiddle.net/7pho1pys/3/), which I believe is the last 1.4 version. It breaks in 1.5.0 (https://jsfiddle.net/7pho1pys/4/), although only once the ngRepeat array has at least 2 elements in it rather than just 1, and the error message is different: It breaks in 1.5.1 (https://jsfiddle.net/v6fmwcy6/3/) with the current error ("Cannot read property 'parent' of undefined") |
Looks like this is another victim of lazy compilation of the transclude function (used by ngIf), introduced in 1.5.0-beta.1. Your example works in 1.5.0-beta.0. It appears that the angular.js/src/ng/directive/ngRepeat.js Line 536 in 9355aea
When you either remove the ngIf from the template or use a local template or remove replace, then it works. Still something that shouldn't happen ideally. You can also remove the wrapper div, but I think it only works somehow, and still not like it should. However, note that replace is deprecated, and you shouldn't use it ideally. I'm not sure if this can be fixed. @dcherman do you want to take a look at this? |
@Narretz I'm game. Might be at least until this weekend before I have time to really dig in since this one might be tricky. The gist of the cause looks to be that the $element passed to the ngRepeat's link function is of Basically, it looks like the NodeList during compilation is getting its offsets messed up somewhere here. |
Yeah, the resulting DOM looks broken. In 1.5.5, the starting comment for the ngIf at the root of the templateUrl is missing:
It should look like this:
|
In fact, I think this is another variation of The reason being the following: <div ng-if="mainCtrl.on">
<div test-dir></div>
<div><div ng-repeat="v in mainCtrl.values"></div></div>
<div>The ng-repeat currently exists</div>
</div> we when calling
Later, the directive when you toggle twice, the transclusion kicks in again this time
but in |
Thanks for investigating @lgalfaso ! I wonder why this is expected:
What's the exact reason the element is removed and not replaced? Why can't we replace it? |
Any news on this issue, guys? There is a directive with I created a simple demo: https://plnkr.co/edit/mJxbEhXoV9PLvEVx44rf?p=preview
and for the second time
|
I have same problem. Simplified, we iterate throught multi-dimensional data array of products and items, where product and item has own directive. We have we downgrade from 1.5.7 do 1.4.12 $scope.dataArray = [
Product 1 Product 2
Product 1 Product 2 |
I will look into this but in the meantime please consider removing the |
Note: for support questions, please use one of these channels: https://github.com/angular/angular.js/blob/master/CONTRIBUTING.md#question. This repository's issues are reserved for feature requests and bug reports.
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When an ngRepeat is with an ngIf which is set to true, then false, then true again (re-creating the
ngRepeat), if the HTML is scructured in a particular way, if causes the ngRepeat to throw and error and fail to render.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).
The bug can reproduced using https://jsfiddle.net/ndhrpz06/23/
Note some salient changes to that repro code which (each individually) cause the error not to occur
<div>
around the test-dir and ng-repeat is removed<div>
wrapping the ng-repeat is removed<div>
is removed, or that<div>
is wrapped in something else so that it isn't the root elementWhat is the expected behavior?
The ngRepeat element should render normally without any errors.
What is the motivation / use case for changing the behavior?
The current behavior is broken. In particular, it can cause unexpected breakages when upgrading from 1.4 to 1.5.
Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
Other information (e.g. stacktraces, related issues, suggestions how to fix)
The error message which is thrown:
angular.js:13550 TypeError: Cannot read property 'parent' of undefined
at Object.enter (angular.js:5396)
at ngRepeatTransclude (angular.js:29009)
at publicLinkFn (angular.js:8276)
at lazyCompilation (angular.js:8615)
at boundTranscludeFn (angular.js:8414)
at controllersBoundTransclude (angular.js:9143)
at ngRepeatAction (angular.js:29003)
at $watchCollectionAction (angular.js:16938)
at Scope.$digest (angular.js:17073)
at Scope.$apply (angular.js:17337)
This may seem like a pretty esoteric bug, but it seems to be indicative of a deeper problem with the directive rendering logic. I would't be surprised if there are other edge condition issues caused by the same underlying bug.
The text was updated successfully, but these errors were encountered: