I want use cropper.js (https://github.com/fengyuanchen/cropperjs) to create an Angular2 cropper with angular-cli.
My directive is:
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);
}
}
The error from ng serve
is: Cannot find module 'cropperjs'
But cropperjs is in node_modules
and my angular-cli.json
is updated with:
"scripts": [
"../node_modules/cropperjs/dist/cropper.js"
],
I do not have any ideas to solve the problem..
I dont think that cropper has typings
so when you do import Cropper from 'cropperjs';
it doesnot work
Simple solution would be in typings.d.ts add
declare var Cropper: any;
It will let typscript to work with cropper as dynamic
Remove import which you have
Right solution would be to import install typings
npm install --save @types/cropperjs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With