2017-09-04 73 views
1

i的角2項目Link如何在Angular 2中包含JQuery插件?

npm i jquery-bootstrap-scrolling-tabs 

安裝jquery插件並添加在.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" 
     ], 

,我使用app.component.ts

聲明名符其實 typings.d.ts

declare var scrollingTabs:any; 

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

錯誤:TypeError: __WEBPACK_IMPORTED_MODULE_1_jquery___default(...)(...).scrollingTabs is not a function

回答

2

你忘了添加jQuery的變量

declare var $ : any

欲瞭解更多信息有關如何添加jQuery的使用這個LINK有和無分型在

+0

增加仍然無法正常工作。滾動Tabs不是一個函數 – sridharan

+0

我建議你使用視圖的孩子,並添加模板引用的功能,而不是類,告訴我,如果你需要一個例子 –

+0

對不起,工作很好,謝謝 – sridharan

1

導入jQuery的你組件文件。

declare let $ : any 
+1

與我添加了9分鐘之前有什麼不同 –

相關問題