离子3照片未在图像选择器中定义

时间:2019-05-15 00:00:17

标签: angular ionic-framework

im使用imagepicker并将其显示在.html中,但其显示的产品错误未定义。

pickImageFromGallery() {

this.imagePicker.getPictures({ maximumImagesCount: 1, outputType: 1 }).then((res) => {
  if (res) {
    if (res.length > 0) {
      debugger;
      this.helper.load();
      const image = `data:image/jpeg;base64,${res}`;
      let id=Date.now();
      const pictures = this.storage.ref('deal/' + id);
      pictures.putString(image, 'data_url').then(r => {
        r.ref.getDownloadURL().then(r => {
          this.deal.photo = r
          this.helper.dismiss();
                              this.helper.toast('Uploaded');

        });
      }, err => {
        this.helper.dismiss();
        console.log(err);
      });
    } else {
      this.helper.toast('you didnt selected any image from the gallary');
      this.helper.dismiss();
    }

  } else {
    this.helper.toast('you didnt selected any image from the gallary');
    this.helper.dismiss();
  }
  //this.user.photo='data:image/jpeg;base64,'+res;


}, (err) => {
  console.log('failed to get images from gallery');

});
 }

.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>

我尝试用photo:string,photo:any;已经。在其他应用程序中,相同的代码与photo:string可以正常工作;但不知道为什么这里显示错误。

0 个答案:

没有答案