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

ng-include on root el of directive with "replace: true" fails with templateUrl, not with template #15314

Closed
andyperlitch opened this issue Oct 25, 2016 · 2 comments

Comments

@andyperlitch
Copy link

andyperlitch commented Oct 25, 2016

Do you want to request a feature or report a bug?
Report a bug

What is the current behavior?
Assume there is a directive called badDir, which is specified as follows:

.directive('badDir', function() {
  return {
    replace: true,
    templateUrl: 'some/url.html', // --> looks like: '<div ng-include="test.html"></div>'
    // ...
  }
})

Then, somewhere it is inside an ng-repeat like so:

<div ng-repeat="i in [1,2,3,4,5]">
  <div bad-dir></div>
</div>

This will result in all bad-dir instances going in the last ng-repeat'ed div. See the plunker below.

Plunker that reproduces:
http://plnkr.co/edit/MyDTWsRbocKW3tScoNRu

What is the expected behavior?

The included bad-dir-like directives should be in their own ng-repeated elements.

What is the motivation / use case for changing the behavior?

This is clearly a bug. The motivation is that it is a pretty severe one.

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.

This bug appears in all versions of 1.5.x (starting from 1.5.0). It does not occur in any previous versions. Tested in firefox and chrome.

Other information (e.g. stacktraces, related issues, suggestions how to fix)

You can fix it by using template instead of templateUrl. I don't really consider this a fix though.

@gkalpak
Copy link
Member

gkalpak commented Oct 26, 2016

This is a known issue. Directives that use transclude: 'element' (such as ngIf, ngInclude, ngRepeat etc) do not work as expected as root nodes of directives with replace: true and templateUrl.

There are ways to work around this, but essentially replace: true is deprecated and bugs such as this are not prioritized (or oftentimes impossible to fix without a major rewrite of the $compile service).

Closing as duplicate of #14326 and #14626. (There are more details on these issues.)

@gkalpak gkalpak closed this as completed Oct 26, 2016
@andyperlitch
Copy link
Author

Thanks for the info @gkalpak.

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

No branches or pull requests

2 participants