1

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')

2 Answers 2

3

You can use require.js for this purpose.

Here is a good article on how to do it.

Sign up to request clarification or add additional context in comments.

Comments

0

Use require.js for this purpose. So you can load modules at run time.

Link--http://requirejs.org/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.