Search code examples
angularthree.jssystemjs

Automatically import additional js with a package using systemjs


I'm using threejs in an Angular 2 app in Typescript and I want to use OrbitControls which is an example of controls for a 3D scene. It is contained within its own js file and has its own typings. I can't get it to load though... I get the following error :

THREE.OrbitControls is not a constructor

The only way I get it to work is by copying the content or the OrbitControls.js file into the three.js main file. Basically what I would like to do is to find a way that I can configure systemjs so that it loads the OrbitControls.js file as if it were a part of the three.js file, if it's even possible.


Solution

  • Does your index.html include script tags for both OrbitControls.js and tree.js?

    It is possible to update someone's library to work without adding the script tags, and to have it import JS code, but the creator of this particular library decided not to. Try to add the export line for that function in tree.js, but there is no guarantee that the code will work.

    I meant to say Try to export that function from OrbitControls and re-export it in tree.js, but there is no guarantee that the code will work.