0

I have a onclick event where I bootstrap a angular module (This is the only way it can be done on the platform I am working on). Now this onclick event on the UI page can be click X times. The first time it is clicked the angular module is correct loaded and I can the see the controller working. Now when I click second time it throws an error.

OnClickEvent() {
    //call ui page (which contains angular script)
}

Angular script

angular.module('myApp', [])
.factory('facotry', ['$http', function($http) {

}])
.controller('controller', function($scope, $attrs, $http) {

});
try{
  angular.module('myApp');
}catch(e){
  angular.bootstrap(document, ["myApp"]); 
}

The error that I get

WARNING: Tried to load angular more than once.
VM65046:6Uncaught Error: [ng:btstrpd] http://errors.angularjs.org/1.6.1/ng/btstrpd?p0=document

How do I make sure that once the module is loaded it is not loaded again on click unless I refresh the page or something ?

Tried but not working

try{
    angular.module('myApp');
}catch(e){
    angular.bootstrap(document, ["myApp"]); 
}
ksernow
  • 662
  • 3
  • 14
  • 33
  • Possible duplicate of [How to check for the existence of a module without an error being raised?](http://stackoverflow.com/questions/19206553/how-to-check-for-the-existence-of-a-module-without-an-error-being-raised) – Félix Adriyel Gagnon-Grenier Jan 26 '17 at 20:47
  • can you explain more about "This is the only way it can be done on the platform I am working on"? I'm not familiar with any platform that would require angular to be bootstrapped in this manner.... – Claies Jan 26 '17 at 21:02
  • The platform already loads angular. The scripts is then injected later on, hence I need to bootstrap angular. I am not sure If i make sense – ksernow Jan 26 '17 at 21:06
  • no, it really doesn't. If the platform already loads angular, then you don't want to bootstrap another copy of angular, you want to locate that module the platform loaded, and add your controllers, services, etc. to that. – Claies Jan 26 '17 at 21:21
  • I am sorry. To be more clear the onclick event creates a popup/dialog where I have a ui page (html/css) which contains angular.js and loads the module. Now everytime you click this is repeated. And there is no where else I can load angular expect on the popup because I dont have access to platform code – ksernow Jan 26 '17 at 21:40

0 Answers0