Pie*_*LOT 7 typescript angular-cli cropper angular
我想使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
错误来自ng serve: Cannot find module 'cropperjs'
但是cropperjs在,node_modules并且我angular-cli.json更新了:
"scripts": [
"../node_modules/cropperjs/dist/cropper.js"
],
Run Code Online (Sandbox Code Playgroud)
我没有任何想法来解决问题..
我不认为剪草机有打字,所以当你这样做时import Cropper from 'cropperjs';它不起作用
简单的解决方案是在typings.d.ts add
declare var Cropper: any;
Run Code Online (Sandbox Code Playgroud)
它会让typscript与cropper一起工作
删除您拥有的导入
正确的解决方案是导入安装类型
npm install --save @types/cropperjs
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4472 次 |
| 最近记录: |