Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Help on task complete handler, UI not updating after variable update inside task event #261

Open
RohanPhpDev opened this issue Apr 28, 2020 · 1 comment

Comments

@RohanPhpDev
Copy link

I am using NativeScript version 6.0 and after successful upload of an image using nativescript-background-http i have created a task complete handler inside i call a function to update array which updates UI but UI is not updating and variable show new data in the console.
here is sample code:
var that=this;
context
.authorize()
.then(function() {
return context.present();
})
.then(function(selection) {
selection.forEach(function(selected) {
var file = selected.android;
var name = file.substr(file.lastIndexOf("/") + 1);
var fileExt=file.substr(file.lastIndexOf(".") + 1);

          var session = bghttp.session("image-upload");
          var request = {
                  url: *******************",
                  method: "POST",
                  headers: {
                      "Content-Type": "application/octet-stream",
                      "file_name":name,
                  },
                  description: "Uploading " + name,
                  androidNotificationTitle: 'Uploading Image',
                  androidDisplayNotificationProgress:true
              };
          
          var task = session.uploadFile(file, request); 
          task.on("responded", (e) => {
            let res=JSON.parse(e.data);
            console.log(res.status);
          });
         task.on("complete", (e) => {
            that.fetch_img();
          });
      });
  }).catch(function (e) {
      console.log(e);
});

fetch_img(){
this.gallery.push({"name":"image.jpg"});
console.log(this.gallery);
}

I have shown gallery variable in .html file using *ngFor it shows some default image but after task complete, a new object is pushed but it not update UI

@PabloPG
Copy link

PabloPG commented Nov 24, 2020

Try add changeDetectorRef.detectChanges();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants