Ionic 3 not updating view

后端 未结 2 463
孤独总比滥情好
孤独总比滥情好 2021-02-05 07:28

Hi I got a function which will update after a http request to the server. It seems that the console.log show that the value has been updated but the UI is not updating unless I

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 08:26

    Try placing this.sv_value = obj.value; inside NgZone.run(); to make Angular detect the change.

    import { Component, NgZone } from "@angular/core";
    ...
    
    export class MyComponentPage {
        constructor(
            private zone: NgZone
            ...
        ){ }
    
        yourFunction(){
            fileTransfer.upload(this.created_image, upload_url, options)
            .then((data) => {
                console.log("success:"+data.response); //This is showing correct response
                var obj = JSON.parse(data.response);
    
                this.zone.run(() => {
                    this.sv_value = obj.value;
                });
    
                console.log(this.value); //This is showing correct value
            }, (err) => {
                console.log("failure:");
            });
        }
    }
    

提交回复
热议问题