7

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..

Pierre-Luc BLOT
  • 429
  • 7
  • 22
  • 1
    how did you manage this to make it, and can help with that, and give an example of how you do it. Thanks – Dkouk Mar 28 '17 at 08:55

1 Answers1

7

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
BlackBeard
  • 10,246
  • 7
  • 52
  • 62
Vova Bilyachat
  • 18,765
  • 4
  • 55
  • 80