[英]_co.onImagePicked is not a function error
I'm using a component that delivers the camera ui and camera functionality.我正在使用一个提供相机用户界面和相机功能的组件。 The actual component is working because I get the view and I also can choose a picture and display it.实际组件正在工作,因为我获得了视图,我还可以选择图片并显示它。 But when it comes to the funtion that I want call with a own listenable event.但是当涉及到我想用自己的可听事件调用的功能时。 I get this error我收到这个错误
_co.onImagePicked is not a function _co.onImagePicked 不是函数
This function is onImagePicked
and I created a output to call it with (imagePick)
这个函数是onImagePicked
,我创建了一个输出来调用它(imagePick)
@Output() imagePick = new EventEmitter<string | File>();
...
onImagePicked(imageData: string | File) {
...
}
I have no idea why since all my other functions are working of this component.我不知道为什么,因为我的所有其他功能都在使用这个组件。
photo-maker.component.ts 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);
}
photo.page.html (where I make user of the comp.) photo.page.html(我在那里让用户使用comp。)
<app-make-photo (imagePick)="onImagePicked($event)"></app-make-photo>
</ion-content>
Save it once again and try it will work.再次保存并尝试它会起作用。 Your logic is right only.只有你的逻辑是对的。
check your package.json file, if the version of capacitor is 1 or higher, to display the image, you have to append 'data:image/jpeg;base64,'
检查你的 package.json 文件,如果电容器的版本是 1 或更高,要显示图像,你必须附加'data:image/jpeg;base64,'
see the below code:看下面的代码:
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);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.