Camera.getPicture在ionic 3中不起作用

时间:2019-01-26 17:51:37

标签: ionic-framework plugins camera

我正在使用相机插件在ionic应用程序中单击图片,但是出现以下错误

OrdercancelPage.html:24 ERROR TypeError: Object(...) is not a function
at Camera.getPicture (index.js:125)
at OrdercancelPage.webpackJsonp.444.OrdercancelPage.getphoto (ordercancel.ts:24)
at Object.eval [as handleEvent] (OrdercancelPage.html:24)
at handleEvent (core.js:13547)
at callWithDebugContext (core.js:15056)
at Object.debugHandleEvent [as handleEvent] (core.js:14643)
at dispatchEvent (core.js:9962)
at core.js:10587
at HTMLButtonElement.<anonymous> (platform-browser.js:2628)
at t.invokeTask (polyfills.js:3)

我的代码是

getphoto(){
this.camera.getPicture({
  quality: 100,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  sourceType: this.camera.PictureSourceType.CAMERA,
  targetWidth: 1024,
  targetHeight: 720
}).then((imageData) => {
  // imageData is a base64 encoded string
  this.base64Image = "data:image/jpeg;base64," + imageData;
}, (err) => {
  console.log(err);
});

}

我正在使用插件

import {   Camera } from '@ionic-native/camera/ngx';

2 个答案:

答案 0 :(得分:5)

只需删除插件并安装-

npm install @ionic-native/camera@4.20.0 

这将解决您的问题

答案 1 :(得分:4)

问题是,我正在使用插件版本5.0.0。我使用package.json降级到4.x.x版本,并且在不使用ngx导入的情况下也可以正常工作。