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

ngRepeat + directive w/ templateUrl + ngIf = printed twice #6006

Closed
@elado

Description

@elado

A really weird case of an ng-repeat, a directive with an external template url and ng-if on root element leads to printing twice every directive.

Happens only with this combination.
Doesn't happen with regular template string, or if the ng-if not on the root element or not in an ng-repeat.

Source:

index.html

<!DOCTYPE html>
<html ng-app="app">
  <head>
    <link rel="stylesheet" href="style.css">
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.10/angular.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body>
    <div ng-repeat="i in [1,2,3]">
      {{i}}
      <hello></hello>
    </div>
  </body>
</html>

script.js

app = angular.module("app", []);

app.directive('hello', function () {
  return {
    restrict: 'E',
    replace: true,
    templateUrl: "hello.html",
    //template: '<div ng-if="true">Printed once as exptected</div>'
  }
});

hello.html

<div ng-if="true">Printed twice, but should not</div>

Or here:

http://plnkr.co/edit/DmyCkta0G0mjzgMJvchk?p=preview

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions