how can I import a js file in angular 6. I tried to implement a navbar and it contains js functions. thanks!!!
I Add my js file called nav.js
"scripts": [
"src/assets/js/nav.js"
]
how can I import a js file in angular 6. I tried to implement a navbar and it contains js functions. thanks!!!
I Add my js file called nav.js
"scripts": [
"src/assets/js/nav.js"
]
Angular 6 has a dedicated place to declare js files within the dedicated arrays of your angular.json, under
and
As an example:
will install a js library under node-modules
The path relative to the project of the js lib file is declared like this:
Then declare in your component the variable(s) to use, either as described by the npm documentation or by @LuaXD
You should include on index.html, e.g:
On this case I included cartodb.js library, then for use cartodb.js on any component, or service I use:
At the beginning of any file (Component, Service, etc).
Note change cartodb by the name of the library you will use, for example for jquery is:
You should have something like this:
P.s Search if the code you want to use doesn't exist in npm.