我用Angular做了一个移动应用程序,我试着用同样的方法在原生应用程序上显示图像,但现在我必须按下一个按钮才能显示这张图像。
currentImageb: any;
public takePhoto() {
console.log('Camera Photo Click');
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
saveToPhotoAlbum: true,
}
this.camera.getPicture(options).then((imageData) => {
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.currentImageb = base64Image;
}, (err) => {
// Handle error
});
}
//Click on Shoh Img Button
showImgB() {
(document.getElementById('b') as HTMLImageElement).src = this.currentImageb;
}// I would like to show my image in the <img> without a button
<ion-button (click)="showImgB()">IMAGE id b</ion-button>
<img src="" id="b">我还想在我的应用程序页面上展示我拍摄的每张照片,而不仅仅是最新的照片。谢谢
发布于 2019-08-20 16:20:28
例如,您不应该使用getElementById来操作DOM。操纵DOM应该是Angular的最后手段。通常情况下,angular提供了一些工具来执行您想要的操作,在这种情况下,只需对变量应用src即可,例如:
<img [src]="currentImageb">https://stackoverflow.com/questions/57569366
复制相似问题