0

如何在 Angular 4 应用程序中使用外部插件?我需要为可滚动的 div 使用 niceScroll 插件,它由组件表示。

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

我从组件线程列表中调用具有 id 可滚动元素的 nicescroll init 函数,如下所示:

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

1 回答 1

0

我猜您正在尝试在 Angular 中使用 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

//在Angular中使用外部js模块

declare var $: any;


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

检查此链接以获取更多信息链接有和没有打字

于 2017-09-07T05:25:25.163 回答