Thomas Vo
Thomas Vo

Reputation: 402

AngularJs and global namespace

I'm working on a project that requires us to embed our AngularJS application to other websites. The application currently uses requireJs to load AngularJS. However, the current AngularJS attach the angular object to window and this can potentially cause conflict with other websites using their own version of AngularJS. I wonder if there's away we can manually place these the angular object into a specific namespace without breaking the code.

Upvotes: 3

Views: 250

Answers (1)

Tomas Kirda
Tomas Kirda

Reputation: 8413

You may try renaming following in the source:

http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js

   /** @name angular */
    angular           = window.angular || (window.angular = {}),

To something custom:

   /** @name angular */
    angular           = window.angularX || (window.angularX = {}),

And then use renamed version in your code: angularX.

Upvotes: 1

Related Questions