如何正确导入ionic中的camanjs?

时间:2018-07-31 03:01:23

标签: angular ionic-framework camanjs

我试图在我的离子项目上安装camanjs。

我添加到我的应用程序模块中:

import * as Caman from 'caman';

将其添加到提供程序中:

@NgModule({

  providers: [
    Caman
  ]
})

在我的home.ts上:

import * as Caman from 'caman';

addBrightness(){
    Caman('#caman-image', function () {
      this.brightness(50).render();
    });
  }

getPicture(sourceType:PictureSourceType) {
    this.camera.getPicture({
      quality: 100,
      destinationType: this.camera.DestinationType.DATA_URL,
      sourceType: sourceType,
      allowEdit: true,
      saveToPhotoAlbum: false,
      correctOrientation: true
    }).then((imageData) => {

      this.selectedImage = `data:image/jpeg;base64,${imageData}`;

    });
  }

以及在我的home.html中:

<button ion-button full (click)="addBrightness()" [disabled]="!selectedImage">Add Brightness</button>

  <img [src]="selectedImage" #caman-image *ngIf="selectedImage">

当我执行ionic cordova emulate browser时,出现此错误:

[09:51:52]  ionic-app-script task: "build" 
[09:51:52]  Error: ./node_modules/canvas/build/Release/canvas.node Module parse failed: Unexpected character '�' (1:0) 
            You may need an appropriate loader to handle this file type. (Source code omitted for this binary file) @ 
            ./node_modules/canvas/lib/bindings.js 3:17-56 @ ./node_modules/canvas/lib/canvas.js @ 
            ./node_modules/caman/dist/caman.full.js @ ./src/app/app.module.ts @ ./src/app/main.ts 
Error: ./node_modules/canvas/build/Release/canvas.node
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
 @ ./node_modules/canvas/lib/bindings.js 3:17-56
 @ ./node_modules/canvas/lib/canvas.js
 @ ./node_modules/caman/dist/caman.full.js
 @ ./src/app/app.module.ts
 @ ./src/app/main.ts

我试图搜索如何将caman正确添加到ionic中,但是我找不到它。

请帮助我如何在离子或角度4中安装和使用caman

0 个答案:

没有答案