javascript - How do I rename or selectively load angularJS? -
we have product widget people load onto site, consists of single js file needs angular run, angular bundled js file.
however, if site using , loading angular themselves, when load our widget error kills following:
warning: tried load angular more 1 time
which makes finish sense since angular indeed loaded more once.
what we'd either of following:
in our script, rename / namespace angular does't conflict host sites loaded angular, or detect if angular loaded, , if don't load angular ourselves.to show examples of our code hard since it's spread on 20 files etc, it's based off next angular seed project uses requirejs load everything, we're compiling single file: https://github.com/tnajdek/angular-requirejs-seed
would appreciate feedback / tips / solutions
nb not duplicate of "check if angular loaded correctly" type questions, angular packaged within our widget js, issue comes when angular loaded parent page. need way rename angular within our package.
i'd advise taking @ answer, has chrome extension running in same circumstance. thought here separate loading of angular website's, , assumes widget loaded after main content of page has been loaded.
if loading in html content ng-app directive or ng-controller, wrap html content in containerng-non-bindable
attribute. angular looks element ng-app attribute when load in angular.js. if 2 ng-apps
nowadays i.e., on site, , widget, cause errors. defer parsing with: window.name = "ng_defer_bootstrap!" + window.name;
load in script. once script has loaded, set window.name '' or whatever before. individually bootstrap (the term angular finding ng-app
attribute) html content using:
var approot = document.queryselector('#id'); angular.bootstrap(approot, ['angularmodulename']);
and should it... caveat, have no thought how work if widget angular on different version client website, , i've made work extensions, little bit different because live in own isolated 'worlds'.
that beingness said, sense should people going in right direction when dealing problem.
javascript angularjs requirejs
No comments:
Post a Comment