How Import JS File in angular 6?

前端 未结 4 1400
忘了有多久
忘了有多久 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:50

    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

提交回复
热议问题