I have a file called moment.js on my local file system and loading it as follows with require.js works:
initialize: function() {
require(['moment'], function(data) {
console.log(data);
});
}
However, if I do:
initialize: function() {
require(['http://momentjs.com/downloads/moment.min.js'], function(data) {
console.log(data);
});
}
data comes back undefined. Why is this? and how do I dynamically include remote modules at runtime?
I noticed that the code you are trying to load hardcodes the module name as moment
so configure RequireJS on the spot so that you can require with the same name:
initialize: function() {
require.config({
paths: { moment: 'http://momentjs.com/downloads/moment.min' }
});
require(['moment'], function(data) {
console.log(data);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With