I encountered an issue with a simple code snippet that involves calling a countdown timer within the catch function of $http.post.
this.$http.post('/api/task/post', updatedTask ,function(data){
alert('success!')
}).catch(function(data){
alert('Error!');
vm.StartTimer(captionClass);
});
Interestingly, when an error occurs, the vm.StartTimer(captionClass) does not execute. However, I found that calling the same function within a click event works as intended.
TestCounter: function(){
vm.StartTimer('.tm-task-caption-title-1');
},
Below is the implementation of the countdown timer function:
StartTimer: function(display) {
var counter = 5;
var interval =setInterval(function() {
$(display).html(counter);
counter--;
if(counter == 0){
clearInterval(interval);
}
}, 1000);
},