I'm trying to create a mobile application using the ionic 2 framework. (Written in Angular 2).
Now I have a FileUpload
option in my app. But this takes a long time when the user has a poor internet connection or something went wrong within the app itself. Now what I want to achieve is to have this fileupload sort of 'timeout' after 7 seconds.
How is this possible in Angular 2?
I was thinking about a workaround having something like this (demo purpose, not the 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);
But this feels like quite a hacky workaround. Is there an option in Angular 2 to do this? Or should I just use the workaround?