I have an application that currently uses Angular 1.7 and we have an IHTTPPromise
(updateCase) where we then process the code on the then()
method after it has resolved
Before the first then()
I want to chain another then()
to set a waiting period of x milliseconds
I cannot use setTimeout()
just in that then as that does not return a Promise.
In Angular 1.7, how can I create a new Promise to contain the setTimeout and then resolve and allow me to have chained then statements?
this.caseService.updateCase(updateCaseRequest)
//***WANT TO ADD A WAIT HERE
.then(
response => {
this.showUpdateComplete();
this.getCases();
this.$scope.selectedCase = selectedCase;
})
}
Use the $timeout Service:
this.caseService.updateCase(updateCaseRequest)
.then( response => {
return this.$timeout( (_ => response) , delay );
}).then( response => {
this.showUpdateComplete();
this.getCases();
this.$scope.selectedCase = selectedCase;
})
The return value of calling $timeout
is a promise, which will be resolved when the delay has passed and the timeout function, if provided, is executed.
For more information, see