简体   繁体   English

将第3方库添加到angular2 cli

[英]Add 3rd party library to angular2 cli

I'm trying to add a third party library to angular2, namely the Flickity slider. 我正在尝试向angular2添加第三方库,即Flickity滑块。

Tried to install typings. 试图安装打字。 When importing them I get en error that @typings/flickity is not a module . 导入它们时,我收到@typings/flickity is not a module错误@typings/flickity is not a module

Second attempt to add it in angular-cli.json . 第二次尝试将其添加到angular-cli.json Added in apps[0].scripts as described in the docs. 如文档中所述在apps[0].scripts添加。 In the component i've used it like this: 在组件中,我已经这样使用它:

this.slider = new Flickity('.news-wrapper', { cellAlign: 'left', contain: true, prevNextButtons: false, pageDots: true }); this.slider = new Flickity('。news-wrapper',{cellAlign:'left',包含:true,prevNextButtons:false,pageDots:true});

When compiling I get an error Cannot find name 'Flickity'. 编译时出现错误, 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. 问题是由于该错误,我无法构建应用程序。

How should it be added then? 那应该如何添加呢?

follow below steps to use flickity in angular-cli based project 按照以下步骤在基于角度的项目中使用轻拂

  1. npm install flickity --save npm install flickity-保存
  2. declare module 'flickity'; 声明模块'flickity'; in typings.d.ts 在types.d.ts中
  3. import * as Flickity from "flickity"; 从“ flickity”中导入*作为Flickity; in app.component.ts (needs to import wherever required) 在app.component.ts中(需要在需要的地方导入)

use it like as you mentioned 像你提到的那样使用它

this.slider = new Flickity('.news-wrapper', { cellAlign: 'left', contain: true, prevNextButtons: false, pageDots: true });

I am not sure if this will work but you can try this in the file that needs flickity. 我不确定这是否行得通,但是您可以在需要轻拂的文件中尝试使用。

let Flickity = require('flickity');

Just make sure you installed let Flickity using NPM 只需确保您安装了让Nick使用Flickity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM