在 Angular (4) 应用程序中初始化外部插件

Init external plugin in Angular (4) app

如何在 angular 4 应用程序中使用外部插件?我需要为可滚动 div 使用 niceScroll 插件,它由 component.

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

我从组件 threads-list 调用 ID 可滚动的元素上的 nicescroll init 函数,像这样:

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

我猜你正试图在 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();
}

查看此 link 了解更多信息 LINK 有无打字