我想使用带有电容相机插件的原生相机。但是在实施之后,我无法再打开页面(当我单击将我路由到该页面的按钮时没有任何反应)我发现错误必须在注释的 html 部分中。但它没有显示错误。当该部分没有评论时,整个应用程序会加载。
page.html
<ion-content>
<!--
<ion-card>
<img
role="button"
class="image"
(click)="onPickImage"
[src]="selectedImage"
*ngIf="selectedImage"
>
</ion-img>
</ion-card>
-->
<ion-footer>
<ion-button (click)="onPickImage()" *ngIf="!selectedImage" class="buttonPost" expand="full" color="primary">Take Photo</ion-button>
</ion-footer>
页面.ts
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { Plugins, Capacitor, CameraSource, CameraResultType } from '@capacitor/core';
@Component({
selector: 'app-cam',
templateUrl: './cam.page.html',
styleUrls: ['./cam.page.scss'],
})
//Native Kamerafunk. importieren hier
export class CamPage implements OnInit {
@Output() imagePick = new EventEmitter<String>();
selectedImage: string;
constructor() { }
onPickImage() {
if (!Capacitor.isPluginAvailable('Camera')) {
return; //falls kein Kamera vorhanden ist.
}
Plugins.Camera.getPhoto({
quality: 50,
source: CameraSource.Prompt, //Prompt heisst entweder Gallery oder Camera vlt stylischer seperater Button hinzufügen
correctOrientation: true,
height: 320,
width: 200,
resultType: CameraResultType.Base64 //Img encoded into a string, can be converted into a file
}).then(image => {
this.selectedImage = image.base64String;
this.imagePick.emit(image.base64String);
}).catch(error => { //Error Handler
console.log(error);
return false;
})
}
onImagePicked(image: string) {
}
ngOnInit() {
}
}