Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript _co.onImagePicked不是函数错误_Javascript_Html_Angular_Typescript_Ionic Framework - Fatal编程技术网

Javascript _co.onImagePicked不是函数错误

Javascript _co.onImagePicked不是函数错误,javascript,html,angular,typescript,ionic-framework,Javascript,Html,Angular,Typescript,Ionic Framework,我正在使用一个组件来提供摄像头用户界面和摄像头功能。 实际的组件正在工作,因为我得到了视图,我还可以选择一张图片并显示它。但是当涉及到我想用自己的可监听事件调用的功能时。我得到这个错误 _co.O不是一个函数 这个函数是onimagepick,我创建了一个输出,用(imagePick) @Output()imagePick=neweventemitter(); ... onImagePicked(图像数据:字符串|文件){ ... } 我不知道为什么,因为我的所有其他功能都在这个组件中工作 p

我正在使用一个组件来提供摄像头用户界面和摄像头功能。 实际的组件正在工作,因为我得到了视图,我还可以选择一张图片并显示它。但是当涉及到我想用自己的可监听事件调用的功能时。我得到这个错误

_co.O不是一个函数

这个函数是
onimagepick
,我创建了一个输出,用
(imagePick)

@Output()imagePick=neweventemitter();
...
onImagePicked(图像数据:字符串|文件){
...
}
我不知道为什么,因为我的所有其他功能都在这个组件中工作

photo-maker.component.ts

   ...
      @ViewChild('filePicker') filePickerRef: ElementRef<HTMLInputElement>;
      @Output() imagePick = new EventEmitter<string | File>();
      selectedImage: string;
      usePicker = false;

      constructor(private sanitizer: DomSanitizer, private router: Router, private plt: Platform,
                  private storage: Storage, private alertCtrl: AlertController) { }


      goCamFi() {
        this.router.navigateByUrl('/camfilter');
      }

      takePicture() {
        if (this.usePicker) {
          this.filePickerRef.nativeElement.click();
        }
        Plugins.Camera.getPhoto({
          quality: 80,
          source: CameraSource.Prompt,
          correctOrientation: true,
          saveToGallery: true,
          allowEditing: true,
          resultType: CameraResultType.Base64,
          direction: CameraDirection.Front
        }).then(image => {
          this.selectedImage = image.base64String;
          this.imagePick.emit(image.base64String);
        }).catch(error => {
          console.log(error);
          return false;
        });
      }

      onImagePicked(imageData: string | File) {
        let imageFile;
        if (typeof imageData === 'string') {
          try {
          imageFile = base64toBlob(imageData.replace('data:image/jpeg;base64,', ''), 'image/jpeg');
          this.storage.set('image_data', imageFile);
          console.log('stored');
          } catch (error) {
            console.log(error);
          }
        } else {
          imageFile = imageData;
        }
      }

      onFileChosen(event: Event) {
        const pickedFile = (event.target as HTMLInputElement).files[0];
        const fr = new FileReader();
        fr.onload = () => {
          const dataUrl = fr.result.toString();
          this.selectedImage = dataUrl;
          this.imagePick.emit(pickedFile);
        };
        fr.readAsDataURL(pickedFile);
      }
。。。
@ViewChild('filePicker')filePickerRef:ElementRef;
@Output()imagePick=neweventemitter();
选择图像:字符串;
usePicker=false;
构造器(专用消毒剂:DOMSANTIZER,专用路由器:路由器,专用plt:平台,
专用存储:存储,专用警报Ctrl:AlertController{}
戈卡姆菲(){
this.router.navigateByUrl('/camfilter');
}
拍照{
if(this.usePicker){
this.filePickerRef.nativeElement.click();
}
Plugins.Camera.getPhoto({
质量:80,
来源:CameraSource.Prompt,
对,,
saveToGallery:没错,
允许:是的,
结果类型:CameraResultType.Base64,
方向:摄像机方向。前方
})。然后(图像=>{
this.selectedImage=image.base64字符串;
this.imagePick.emit(image.base64String);
}).catch(错误=>{
console.log(错误);
返回false;
});
}
onImagePicked(图像数据:字符串|文件){
让图像文件;
如果(图像数据的类型=='string'){
试一试{
imageFile=base64toBlob(imageData.replace('data:image/jpeg;base64',''),'image/jpeg');
this.storage.set('image\u data',imageFile);
console.log('stored');
}捕获(错误){
console.log(错误);
}
}否则{
imageFile=图像数据;
}
}
onFileChosen(事件:事件){
const pickedFile=(event.target作为HTMLInputElement.files[0];
const fr=new FileReader();
fr.onload=()=>{
const dataUrl=fr.result.toString();
this.selectedImage=dataUrl;
this.imagePick.emit(pickedFile);
};
fr.readAsDataURL(pickedFile);
}
photo.page.html(我在这里使用comp。)


再次保存,然后再试一次即可。你的逻辑是正确的

检查package.json文件,如果电容器的版本为1或更高, 要显示图像,您必须附加
”数据:image/jpeg;base64'

请参阅以下代码:

onPickImage() {
    if(!Capacitor.isPluginAvailable('Camera')) {
      this.filePickerRef.nativeElement.click();
      return;
    }
    Plugins.Camera.getPhoto({
      quality: 50,
      source: CameraSource.Prompt,
      correctOrientation: true,
      height: 640,
      width: 640,
      resultType: CameraResultType.Base64
    }).then(image => {
      this.selectedImage = 'data:image/jpeg;base64,' + image.base64String;
      this.imagePick.emit(image.base64String);
    })
<app-make-photo (imagePick)="onImagePicked($event)"></app-make-photo>
</ion-content>
onPickImage() {
    if(!Capacitor.isPluginAvailable('Camera')) {
      this.filePickerRef.nativeElement.click();
      return;
    }
    Plugins.Camera.getPhoto({
      quality: 50,
      source: CameraSource.Prompt,
      correctOrientation: true,
      height: 640,
      width: 640,
      resultType: CameraResultType.Base64
    }).then(image => {
      this.selectedImage = 'data:image/jpeg;base64,' + image.base64String;
      this.imagePick.emit(image.base64String);
    })