How to include JQuery plugins in Angular 2?

主宰稳场 提交于 2019-12-01 10:19:12

问题


i installed jquery plugin in angular 2 project Link

npm i jquery-bootstrap-scrolling-tabs

and add in .angular-cli.json

 "styles": [
        "styles.css",
        "../node_modules/jquery-bootstrap-scrolling-tabs/dist/jquery.scrolling-tabs.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
         "../node_modules/jquery-bootstrap-scrolling-tabs/dist/jquery.scrolling-tabs.js"
      ],

and i declare the veritable typings.d.ts

declare var scrollingTabs:any;

using in app.component.ts

ngAfterViewInit() {
    $('.nav-tabs').scrollingTabs({
      scrollToTabEdge: true  
    });
  } 

error: TypeError: __WEBPACK_IMPORTED_MODULE_1_jquery___default(...)(...).scrollingTabs is not a function


回答1:


you forgot to add the jquery variable

declare var $ : any

For more info on how to add jquery use this LINK with and without typings




回答2:


Import jquery in your component file.

declare let $ : any


来源:https://stackoverflow.com/questions/46031112/how-to-include-jquery-plugins-in-angular-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!