I'm in the process of developing a mobile application with the Ionic 2 framework, utilizing Angular 2.
One of the features I have implemented is a FileUpload
option, which unfortunately experiences delays in cases of poor internet connections or app malfunctions. My goal is to set a timeout for this file upload after 7 seconds.
Is there a way to achieve this timeout within Angular 2?
My initial thought was to implement a workaround similar to the following (for demonstration purposes only, not actual code):
let doneUploading: boolean = false;
this.http.post(url, data, options).subscribe(response => {
doneUploading = true;
....
}, err => {
doneUploading = true;
....
});
setTimeout(()=> {
if(!doneUploading) {
alert("TIMEOUT");
}
}, 7000);
Although this workaround gets the job done, it feels somewhat hacky. Is there a more streamlined solution within Angular 2, or should I stick with this workaround?