Angular(4)app中的Init外部插件

时间:2017-09-06 23:05:57

标签: javascript angular nicescroll

如何在angular 4 app中使用外部插件?我需要将niceScroll插件用于可滚动的div,它由组件表示。

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

我在id为可滚动的元素上调用nicescroll init函数,从组件 threads-list 中调用:

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

1 个答案:

答案 0 :(得分: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();
}

检查此链接以获取更多信息LINK,包括和不包含