Reputation: 4102
How can I load module script dynamically.
I have 2 JS files:
module1.js
(function() {
var mod = angular.module('module1', []);
....
})();
This is the second:
module2.js
(function() {
var mod = angular.module('module2', ['module1']);
....
})();
I want to load the module1.js dynamically when it is required in module2.js.
There are any way to "map" modules name with the source URL? Something like this:
angular.registerModuleSource('module1', 'http://myhost.com/app/module1.js')
angular.registerModuleSource('module2', 'http://myhost.com/app/module2.js')
Upvotes: 1
Views: 3359
Reputation: 2110
Use require.js for this purpose. So you can load modules at run time.
Link--http://requirejs.org/
Upvotes: 0
Reputation: 4141
You can use require.js for this purpose.
Here is a good article on how to do it.
Upvotes: 3