将第3方库添加到angular2 cli [英] Add 3rd party library to angular2 cli
问题描述
我正在尝试向angular2添加一个第三方库,即Flickity滑块.
I'm trying to add a third party library to angular2, namely the Flickity slider.
试图安装类型.导入它们时,出现错误@typings/flickity is not a module
.
Tried to install typings. When importing them I get en error that @typings/flickity is not a module
.
第二次尝试将其添加到angular-cli.json
中.如文档中所述在apps[0].scripts
中添加.
在组件中,我已经这样使用它:
Second attempt to add it in angular-cli.json
. Added in apps[0].scripts
as described in the docs.
In the component i've used it like this:
this.slider = new Flickity('.news-wrapper',{ cellAlign:'左', 包含:true, prevNextButtons:否, pageDots:正确 });
this.slider = new Flickity('.news-wrapper', { cellAlign: 'left', contain: true, prevNextButtons: false, pageDots: true });
编译时出现错误Cannot find name 'Flickity'.
,但是运行该网站时,它就像一个超级按钮.
When compiling I get an error Cannot find name 'Flickity'.
, but when running the site it works like a charm.
问题是由于该错误,我无法构建应用.
The problem is I can't build the app because of that error.
那应该怎么添加呢?
推荐答案
按照以下步骤在基于angular-cli的项目中使用轻拂性
follow below steps to use flickity in angular-cli based project
- npm install flickity --save
- 声明模块"flickity";在types.d.ts中
- 从"flickity"中导入*作为Flickity;在app.component.ts中(需要在需要的地方导入)
像您提到的那样使用它
this.slider = new Flickity('.news-wrapper', { cellAlign: 'left', contain: true, prevNextButtons: false, pageDots: true });
这篇关于将第3方库添加到angular2 cli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!