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

ngRepeat breaks when re-created by ngIf under certain circumstances #14626

Open

Description

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

  • if the 'ng-if' attribute of the <div> around the test-dir and ng-repeat is removed
  • if the ng-repeat is removed or the repeated array remains empty
  • if the extra <div> wrapping the ng-repeat is removed
  • if the 'replace' setting testDir is set to false instead of true,
  • if the 'ng-if' attribute of the testDir template's root <div> is removed, or that <div> is wrapped in something else so that it isn't the root element
  • if the testDir is replaced in the main HTML with its own template string
  • if the testDir template string is applied directly to the 'template' setting of the dir, rather than via 'templateUrl' and $templateCache

What 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions