nativescript-background-http
nativescript-background-http copied to clipboard
Need Help on task complete handler, UI not updating after variable update inside task event
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
Try add changeDetectorRef.detectChanges();