I need help with adding alerts using Angular Bootstrap that should dismiss themselves after a certain timeout. However, the alerts are not dismissing on their own. Here's the code snippet:
angular.module('ui.services').service('AlertService', [
function () {
var alerts = [];
this.add = function(type, msg){
var self = this;
return alerts.push({
type: type,
msg: msg,
close: function() {
return self.closeAlert(this);
}
});
$timeout(function(){
self.closeAlert(this);
}, 3000);
},
this.closeAlert = function(alert) {
return this.closeAlertIdx(alerts.indexOf(alert));
},
this.closeAlertIdx = function(index) {
return alerts.splice(index, 1);
},
this.alertData = function() {
return alerts;
}
}]);
I have added a timeout but it doesn't seem to be working as expected. Any ideas what could be causing the issue?