Sinuhé Valencia
Sinuhé Valencia

Reputation: 31

Use an external JS file (File A) that needs another JS file (File B) into a TypeScript file using Angular 4?

I'm working with Angular 4 and I have installed two external JS libraries with npm and now I have them in the node_modules folder and I can use them in another TS file into my project, but the thing is that the import B, needs the import A, so I just can't use them in a single TS file because the import B does't find the needed elements from A.

Does anyone know how could I solve this?

I tried importing both files in the same TS file but didn't work.

Thank you so much!

Upvotes: 0

Views: 35

Answers (1)

rjustin
rjustin

Reputation: 1439

If you installed the with NPM and are using the Angular CLI you do NOT need them in the scripts section in your angular-cli.json this is only used for scripts included in other ways and equates to inlining script tags.

All you need to do is use this statement in File A:

import {NameOfModule} from "name of file B";

Usually you can find this in the package documentation but if this doesn't work you need to find the top level module that the library is exporting often found in an index file.

If import A needs import B it should be doing that on its end not on your end.

Upvotes: 1

Related Questions