离子2中的UI不会更新图像。如何动态显示更改图像?

时间:2018-01-29 13:01:21

标签: ionic-framework

我从相机拍摄照片并上传到服务器,然后从服务器返回图片的网址。但是之前的图片仍在那里。图片没有更新。

1 个答案:

答案 0 :(得分:1)

您必须在TYPESCRIPT中创建一个类似于:

的变量
path:String = "";

然后拍摄照片的功能

    takePicture(){
        Camera.getPicture({
            destinationType: Camera.DestinationType.DATA_URL,
            targetWidth: xxx,
            targetHeight: yyy
        }).then((imageData) => {
          // imageData is a base64 encoded string, 
            this.path = "data:image/jpeg;base64," + imageData;
//create a function here to send the photo and the return will be the link
            this.path = getServerLink();
        }, (err) => {
            console.log(err);
        });
      }

然后在HTML中

      <img src="{{path}}"/>  
<!--or -->
    <img [src]="path" *ngIf="path" />