How Import JS File in angular 6?

前端 未结 4 1426
时光取名叫无心
时光取名叫无心 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 10:03

    first, you should install your library with npm. then the library is being added to your node_modules folder, in your project.

    now:

    if you want to import js files into the angular project, first you should check the version of angular, if you are using version 2 and 4 , you should write like this :

          "scripts": [ "../node_modules/jquery/dist/jquery.min.js" ]
    

    and if you are using version upper than 4, like 5,6 or 7 you should write like this :

          "scripts": [ "./node_modules/jquery/dist/jquery.min.js" ]
    

    in this example i import jquery into the angular project. i hope, it works

提交回复
热议问题