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

ng-repeat behaves weirdly if angular is accidentally loaded twice or more #5587

Closed
spirographer opened this issue Dec 31, 2013 · 5 comments
Closed

Comments

@spirographer
Copy link

The app below demonstrates how ng-repeat will square, cube, etc. the number of items in a table depending on how many times angular.js is loaded in the page.

<html ng-app="brokentable">
<head>
    <title>Broken Angular Table</title>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
  <script>
    if (!window.angular) {
      document.write('<script src="angular.min.js"><\/script>');
    }
  </script>
  <script type="text/javascript">
        var app = angular.module('brokentable', []);

        app.controller('BrokenTable', function($scope) {
            $scope.headings = ['One', 'Two', 'Three'];
            $scope.fillings = [[1, 2, 3], ['A', 'B', 'C'], [7, 8, 9]];
        });
  </script>
</head>
<body ng-controller="BrokenTable">
    <table>
    <tr>
      <th ng-repeat="heading in headings">{{heading}}</th>
    </tr>
    <tr ng-repeat="filling in fillings">
      <td ng-repeat="fill in filling">{{fill}}</td>
    </tr>
  </table>
</body>
</html>
@gsklee
Copy link
Contributor

gsklee commented Jan 5, 2014

This can be fixed but in many manners. Would be good to know what's the best way to approach this.

@IgorMinar
Copy link
Contributor

I think that we should have a check in angular that would prevent full angular.js being loaded more than once.

The check should take into account that it's ok to load angular-loader.js once before loading angular.js.

@IgorMinar
Copy link
Contributor

PRs Welcome!

@spirographer
Copy link
Author

Makes sense to me, but I'm not an expert on the innards of the library.

On Monday, January 6, 2014, Igor Minar wrote:

I think that we should have a check in angular that would prevent full
angular.js being loaded more than once.

The check should take into account that it's ok to load angular-loader.js
once before loading angular.js.


Reply to this email directly or view it on GitHubhttps://github.com//issues/5587#issuecomment-31700052
.

@onaclov2000
Copy link

In a way is the goal be to make the loaded JS 'more' in line with a singleton pattern? Are there cases someone might actually need to load the JS file twice? (I can't think of a use case but maybe someone has one?) If that's the case, would mimiking a particular behavior be necessary as well?

@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.1, 1.2.14 Mar 1, 2014
@btford btford modified the milestones: 1.3.0-beta.2, 1.3.0-beta.1 Mar 10, 2014
@IgorMinar IgorMinar self-assigned this Mar 10, 2014
@tbosch tbosch modified the milestones: 1.3.0-beta.3, 1.3.0-beta.2 Mar 14, 2014
vojtajina pushed a commit that referenced this issue Mar 21, 2014
This is hard to test as a unit-test, since it involves the actual loading
of angular, but it turns out that it is easy to test using a protractor
e2e test.

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

No branches or pull requests

6 participants