2017-09-06 47 views
0

如何在角度4應用程序中使用外部插件?我需要爲可滾動的div使用niceScroll插件,它由組件表示。在Angular(4)應用程序中初始化外部插件

<div class="d-flex" id="scrollable"> 
    <app-threads-list></app-threads-list> 
</div> 

我打電話nicescroll初始化功能元件上的ID滾動,從組件線程列表這樣的:

$('#scrollable').niceScroll(); 

回答

0

我猜你是想在角使用jquery。

沒有分型 第一步

npm install jquery --save 

第二步

Add the jquery scripts file in .angular-cli.json file 


"scripts": [ "../node_modules/jquery/src/jquery-min.js" ] 

第三步

Adding a var in component to be used as a global variable 

//使用外部JS模塊角

declare var $: any; 


Then in ngAfterViewInit(){ 
    $('#scrollable').niceScroll(); 
} 

檢查此鏈接獲取更多信息LINK有和無分型