How Import JS File in angular 6?

前端 未结 4 1389
忘了有多久
忘了有多久 2021-02-10 09:30

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         


        
4条回答
  •  情深已故
    2021-02-10 09:39

    Angular 6 has a dedicated place to declare js files within the dedicated arrays of your angular.json, under

     /projects/$(youProjectName)/architect/build/options/scripts[]
    

    and

     /projects/$(youProjectName)/architect/test/options/scripts[]
    

    As an example:

    npm install fast-levenshtein --save
    

    will install a js library under node-modules

    The path relative to the project of the js lib file is declared like this:

    "scripts": [
       "node_modules/fast-levenshtein/levenshtein.js"
    ]
    

    Then declare in your component the variable(s) to use, either as described by the npm documentation or by @LuaXD

提交回复
热议问题