-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat(noConflict): restore previous namespace #1535
Conversation
@@ -58,6 +58,8 @@ var Error = window.Error, | |||
push = [].push, | |||
toString = Object.prototype.toString, | |||
|
|||
|
|||
_angular = window.angular, | |||
/** @name angular */ | |||
angular = window.angular || (window.angular = {}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tried your patch, but looking at this line, it seems Angular will reuse any existing window.angular
and extend it. This goes directly against the principle of returning the old value unchanged, and in fact turns noConflict()
into a no-op.
@mernen you were correct about the noop I have updated the pull request. I would like to add a spec for this.. In order to test I would like to load 2 versions of angular on the page and then test to make sure they are different objects. I'm not exactly sure where in the testing framework I can add another angular script tag during a test run. I would dynamically load the angular script in the spec, but im not sure thats the best approach. |
Thanks for your contribution! In order for us to be able to accept it, we ask you to sign our CLA (contributor's license agreement). CLA is important for us to be able to avoid legal troubles down the road. For individuals (a simple click-through form): For corporations (print, sign and scan+email, fax or mail): |
@mhevery i just signed the CLA |
MERGED, thanks |
Does this mean noConflict is in a released version of AngularJS? |
I don't see noConflict in production angular file. |
Very sad to see this feature missing from production. This is an important requirement for API vendors who use Angular. |
It looks like this was removed (for some reason) in 9faabd1 which is sad since I was looking to create a self contained embeddable app. A hack can be done by creating a custom wrapper which sets window.angular to null (after backing up any existing instance), loading in angular, then restoring window.angular to the original reference afterward. |
so where do we stand with this? |
I also have need to build widgets to be used by third party sites and am interested in not having our version of angular conflict with the host site's version. Is an official noConflict() in the works? |
#8596 (won't land in its current form) |
@devourment77 I worked around the lack of noConflict by isolating Angular in a same domain iframe. Then I manually bootstrapped my angular widgets. I used angular as a UI framework for a thirdparty ad network. Angular couldn't be introduced globally on the publisher's pages so the iframe provided the needed isolation. The widgets were not rendered in the iframe. They were rendered on the host page, but a same domain can access the DOM of the parent page. So angular could bootstrap the widgets if I provided the element. |
@treasonx Thanks for the idea. Right now I am trying to following this method: http://www.mattburkedev.com/multiple-angular-versions-on-the-same-page/ by for whatever reason, the closure version of angular is still creeping out to the main DOM. Did you run into any of the JSONP issues? |
@devourment77 we are getting off topic this will be my last reply about iframes here: I didn't use anything besides the bindings and directives. I would assume that JSONP would just work since the script tags created by angular would be in the context of the iframe. Look at lightningjs they have a robust way of creating the same domain iframe. I used them as inspiration when I was creating my same domain iframe If you are writing third-party js a hidden same domain iframe provides the best isolation! I would never write third-party js without one! |
Angular needs to provide a way to restore the previously defined
angular
global namespace to prevent conflict with existing scripts. This is especially important if there are multiple versions of angular loaded onto the same page. If angular is used in a thirdparty javascript environment it should provide a way to clean up the global after loading.This feature is similiar to the jQuery noConflict function.