【问题标题】:ionic 3 show image of imagepicker or capture by camera in htmlionic 3 显示图像选择器的图像或在 html 中通过相机捕获
【发布时间】:2019-09-30 22:38:19
【问题描述】:

我需要在 .html 中显示捕获图片或选定图片的图像。这就是我的显示方式,但在此它的照片显示错误未定义。我尝试使用照片:任何;照片:字符串;但没有解决。

<ion-grid>
        <ion-row>
                <ion-col col-12 text-center>
                  <ion-img (click)="setImage()" style="width:120px;height:120px"  [src]="deal?.photo || 'https://cdn.dribbble.com/users/21845/screenshots/3938419/placeholder.png'" height="120px"></ion-img>    
                </ion-col>
              </ion-row>
</ion-grid>

.ts

takePicture() {
this.camera.getPicture(this.options).then((imageData) => {
  this.helper.load();

  let id=Date.now();
  const image = `data:image/jpeg;base64,${imageData}`;
  const pictures = this.storage.ref('deal/'+id);
  pictures.putString(image, 'data_url').then((r: UploadTaskSnapshot) => {
      r.ref.getDownloadURL().then(res=>{
       this.deal=res;  // here is the image i want to show 
       this.helper.dismiss();
      })

  }, err => {
    console.log(err);
    this.helper.toast(err);
    this.helper.dismiss();
  });

}, (err) => {
  console.log(err);

});
}

我正在使用某个代码。以前它使用 this.deal.photo = res 。这也在努​​力上传到firebase,但显示未定义的错误照片。当我删除照片时,它的工作但没有在 .html 中显示图像。

我需要知道如何在 home.html 中显示交易,以前我显示像 [src]="deal?.photo" 我做的像 [src]="deal" 所以它显示一些令牌错误

【问题讨论】:

  • 建议您检查 res 是否包含照片键和值。

标签: angular ionic-framework


【解决方案1】:

图片网址可能附加了一个“文件”前缀,可以通过调用删除:

this.deal=normalizeURL(res);

或者也许(我不能从你的代码中完全看出):

this.deal.photo=normalizeURL(res);

您可以阅读有关 normalizeURL here 的信息。

【讨论】:

  • 不,它是 Ionic 的一部分。 “normalizeURL”你拼错了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-19
  • 2017-04-27
  • 1970-01-01
  • 1970-01-01
  • 2018-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多