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

fix(re-bootstrap): Throw an error when bootstrapping a bootstrapped element #3411

Closed
wants to merge 2 commits into from

Conversation

jeffbcross
Copy link
Contributor

Nothing would prevent a user from accidentally calling angular.bootstrap on an element that had already been bootstrapped. If this was done, odd behavior could manifest in an application, causing different scopes to update the same DOM, and causing debugger confusion.

This fix adds a check inside of angular.bootstrap to check if the passed-in element already contains a class of ng-scope, and if so, will throw an error.


var classes = element.attr('class');
var SCOPE_CLASS = /([^A-Za-z0-9\-\_]ng\-scope|^ng\-scope)(?!\S)/;
if (SCOPE_CLASS.test(classes)) throw ngMinErr('btstrpd', "Element '{0}' is already bootstrapped", element[0].outerHTML);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with

if (!angular.injector()) throw

@jeffbcross
Copy link
Contributor Author

@mhevery I get odd behavior when I use element.injector() to determine if an element has already been bootstrapped. This line causes all e2e tests to fail.

if (element.injector()) throw ngMinErr('btstrpd', "Element '{0}' is already bootstrapped", element[0] ? element[0].outerHTML : '');

If I change element.injector() to element.hasClass('ng-scope'), everything is fine. I'll try to track down why this side effect is present, but wondered if you had an idea.

@@ -0,0 +1,4 @@
@ngdoc error
@name ng:btstrpd
@fullName Element Already Bootstrapped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we say "App Already Bootstrapped with this Element" instead? "bootstrapping and element" doesn't make much sense to me.

This is necessary to make e2e tests pass for implementing angular#3411. At present, the docs are violating the rule being enforced by double-bootstrap prevention.
@jeffbcross
Copy link
Contributor Author

Note this PR is rebased against the branch from #3458, because tests require a fix from that branch. Once that PR gets merged, this PR will be down to one commit.

jeffbcross added a commit that referenced this pull request Aug 9, 2013
This is necessary to make e2e tests pass for implementing #3411. At present, the docs are violating the rule being enforced by double-bootstrap prevention.
@jeffbcross
Copy link
Contributor Author

…lement.

Nothing would prevent a user from accidentally calling angular.bootstrap on an element that had already been bootstrapped. If this was done, odd behavior could manifest in an application, causing different scopes to update the same DOM, and causing debugger confusion.

This fix adds a check inside of angular.bootstrap to check if the passed-in element already contains a class of ng-scope, and if so, will throw an error.
@jeffbcross
Copy link
Contributor Author

@jeffbcross
Copy link
Contributor Author

Merged

@jeffbcross jeffbcross closed this Aug 9, 2013
@Vinoth18
Copy link

I just upgraded the Angular to 1.2.8.

I am initializing and opening a model from GWT using $wnd.angular.bootstrap($doc, ['fmEventLogApp']);

After closing the model, when I try to open the model again, it is try to reinitialize the model again and it is throwing an error as "uncaught exception: com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses"

But when i see the error message, it says "App Already Bootstrapped with this Element".

How to solve this problem in case of a model window? Please help.

@jeffbcross
Copy link
Contributor Author

Are you manually calling angular.bootstrap somewhere in the process of opening the modal? Or is the ng-app directive being used inside the modal? Either of these behaviors would cause the problem.

@Vinoth18
Copy link

Inside my GWT code, I am using $wnd.angular.bootstrap to open the modal. Other than this, I am not using angular.bootstrap or ng-app directive. This might be fixed differently by using the modal injector which is returned by the angular.bootstrap, I think. Going to try that now.

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

Successfully merging this pull request may close these issues.

4 participants