Multiple versions of AngularJS in one page

后端 未结 4 938
予麋鹿
予麋鹿 2020-12-05 05:46

What issues might I experience in having two different versions of AngularJS loaded into one page?

Obviously this seems like a stupid thing to do, b

4条回答
  •  再見小時候
    2020-12-05 06:14

    Great question! Like you, we were unable to uncover much on this topic...we are in the process of deploying a version of Angular with our product which will be embedded within client websites that could also have Angular already loaded.

    Here is what we have done:

    1. Modify the Angular source - do not use "window.angular" or "angular" in your implementation, choose some other variable or object property to house it. If you do use "window.angular" and/or "angular", it could break both applications if the versions are different.
    2. Rename all delivered objects (directives, etc); otherwise, the other version of angular could attempt to process your directives.
    3. Rename all CSS classes used by Angular (ng-cloak, etc). This will allow you to style your version of Angular separately from the other version.
    4. Manually bootstrap your application, as described by 'kseb' above.

    If you are going to completely name space AngularJS as I have described here, take care to not do a global search and replace because angular does need a "window" reference for registering events, and a few other places.

    I just finished doing this at work and I am in the process of testing. I will update this answer with my results.

提交回复
热议问题