|
689 | 689 | * @returns {boolean} |
690 | 690 | */ |
691 | 691 | function moduleExists(moduleName) { |
| 692 | + if(!angular.isString(moduleName)) { |
| 693 | + return false; |
| 694 | + } |
692 | 695 | try { |
693 | | - return angular.module(moduleName); |
| 696 | + return ngModuleFct(moduleName); |
694 | 697 | } catch(e) { |
695 | 698 | if(/No module/.test(e) || (e.message.indexOf('$injector:nomod') > -1)) { |
696 | 699 | return false; |
|
700 | 703 |
|
701 | 704 | function getModule(moduleName) { |
702 | 705 | try { |
703 | | - return angular.module(moduleName); |
| 706 | + return ngModuleFct(moduleName); |
704 | 707 | } catch(e) { |
705 | 708 | // this error message really suxx |
706 | 709 | if(/No module/.test(e) || (e.message.indexOf('$injector:nomod') > -1)) { |
|
775 | 778 | continue; |
776 | 779 | } |
777 | 780 | var newModule = regModules.indexOf(moduleName) === -1; |
778 | | - moduleFn = angular.module(moduleName); |
| 781 | + moduleFn = ngModuleFct(moduleName); |
779 | 782 | if(newModule) { // new module |
780 | 783 | regModules.push(moduleName); |
781 | 784 | register(providers, moduleFn.requires, params); |
|
888 | 891 | } |
889 | 892 | }); |
890 | 893 | } |
| 894 | + |
891 | 895 | if(initModules.length === 0) { |
892 | 896 | throw 'No module found during bootstrap, unable to init ocLazyLoad'; |
893 | 897 | } |
|
909 | 913 | angular.forEach(initModules, function(moduleName) { |
910 | 914 | addReg(moduleName); |
911 | 915 | }); |
| 916 | + |
| 917 | + initModules = []; // reset for next bootstrap |
| 918 | + angular.module = ngModuleFct; // restore angular.module |
912 | 919 | } |
913 | 920 |
|
914 | | - var bootstrap = angular.bootstrap; |
| 921 | + var bootstrapFct = angular.bootstrap; |
915 | 922 | angular.bootstrap = function(element, modules, config) { |
916 | 923 | initModules = modules.slice(); // make a clean copy |
917 | | - return bootstrap(element, modules, config); |
| 924 | + return bootstrapFct(element, modules, config); |
| 925 | + }; |
| 926 | + |
| 927 | + var addToInit = function addToInit(name) { |
| 928 | + if(angular.isString(name) && initModules.indexOf(name) === -1) { |
| 929 | + initModules.push(name); |
| 930 | + } |
918 | 931 | }; |
919 | 932 |
|
| 933 | + var ngModuleFct = angular.module; |
| 934 | + angular.module = function(name, requires, configFn) { |
| 935 | + addToInit(name); |
| 936 | + return ngModuleFct(name, requires, configFn); |
| 937 | + }; |
| 938 | + |
| 939 | + // add unit tests support |
| 940 | + if((window.jasmine || window.mocha) && angular.isDefined(angular.mock)) { |
| 941 | + var ngMockModuleFct = angular.mock.module; |
| 942 | + var windowMockModuleFct = window.module; |
| 943 | + window.module = angular.mock.module = function(module) { |
| 944 | + var moduleFns = Array.prototype.slice.call(arguments, 0); |
| 945 | + if (angular.isObject(module) && !angular.isArray(module)) { |
| 946 | + angular.forEach(module, function(value, key) { |
| 947 | + addToInit(key); |
| 948 | + }); |
| 949 | + } else if(angular.isString(module)) { |
| 950 | + addToInit(module); |
| 951 | + } |
| 952 | + ngMockModuleFct(module); |
| 953 | + } |
| 954 | + } |
| 955 | + |
920 | 956 | // Array.indexOf polyfill for IE8 |
921 | 957 | if(!Array.prototype.indexOf) { |
922 | 958 | Array.prototype.indexOf = function(searchElement, fromIndex) { |
|
0 commit comments