Load AMD Module conditionally in runtime

Topics: General
Feb 14, 2013 at 8:04 AM
Hello, is it possible to import amd module within another module or class? I mean with requirejs is it possible to conditionally load modules in runtime. From typescript i know just the method with import xy = module("xy"), but this statement should be in global namespace? Or am i missing something?
Coordinator
Feb 14, 2013 at 3:05 PM
Yes, you can import modules from other external modules. When you compile, you can select whether to output CommonJS or AMD using the --module flag.

Currently, the external module support in TypeScript (using 'import') expects that the modules you're loading won't change.
Feb 14, 2013 at 6:33 PM
You can use import on the top of the typescript file, if it is defined in global context. How can i import a module within class function? Is it possible?
Developer
Feb 17, 2013 at 4:54 PM
There is an example of how to do this in section 9.4.2 of the Language Specification. The example is for CommonJS (synchronous) modules, but you can easily adapt it to AMD by using the asynchronous version of the 'require' function.
Feb 17, 2013 at 5:34 PM
Thank you Anders, your advice was helpful. You and your team make great work. Keep it up!