I've encountered an issue with the code below, where a message is displayed if a promise doesn't return after five seconds:
$timeout(function () {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - created'
}],
type: 'error'
};
return;
}
}, 5000)
However, I only want this message to display for two seconds. I tried nesting timeouts and it achieved the desired result. Is it considered bad practice to use nested timeouts?
$timeout(function () {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - Railcar ASN created'
}],
type: 'error'
};
$timeout(function(){
$scope.message = null;
}, 2000)
return;
}
}, 5000)
Update: Following the advice provided here, I made the following adjustment:
$timeout(function () {
if (!$scope.promiseComplete && $scope.submitted) {
$scope.message = {
content: [{
title: '',
msg: 'Service down - created'
}],
type: 'error'
};
return $timeout(function(){
$scope.message = null;
}, 2000)
}
}, 5000)