我想使用 cropper.js ( https://github.com/fengyuanchen/cropperjs ) 通过 angular-cli 创建一个 Angular2 裁剪器。
我的指令是:
import {Directive, ElementRef, Input, OnInit} from '@angular/core';
import Cropper from 'cropperjs';
@Directive({
selector: '[ng2-cropper]'
})
export class Ng2CropperJsDirective implements OnInit {
@Input('options') options: any = {};
private cropper;
constructor(private _element: ElementRef) { }
ngOnInit(): void {
console.log(Cropper);
this.cropper = new Cropper(this._element.nativeElement, this.options);
}
}
ng serve
的错误是:Cannot find module 'cropperjs'
但是 cropperjs 在 node_modules
中并且我的 angular-cli.json
更新为:
"scripts": [
"../node_modules/cropperjs/dist/cropper.js"
],
我没有任何解决问题的想法..
最佳答案
我不认为 cropper 有打字
所以当你 import Cropper from 'cropperjs';
它不起作用
简单的解决方案是在 typings.d.ts 中添加
declare var Cropper: any;
它将让 typscript 以动态方式与 cropper 一起工作
删除你的导入
正确的解决方案是导入 install typings
npm install --save @types/cropperjs
关于angular - 如何通过 angular-cli 将 Cropper.js 用于 Angular2 项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41841045/