How Import JS File in angular 6?

前端 未结 4 1428
时光取名叫无心
时光取名叫无心 2021-02-10 09:19

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:52

    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

提交回复
热议问题