Joined November 2013
·
Posted to
Angular-UI Bootstrap alert service for Angular.js
over 1 year
ago
Is there a way to use $timeout for closing alerts?
alertService.add = function(type, msg, timeout) {
$rootScope.alerts.push({'type': type, 'msg': msg , close: alertService.closeAlert(this) });
timeout
if (timeout) {
$timeout(function(){
$rootScope.closeAlert($rootScope.alerts.indexOf(alert));
}, timeout);
}
};
Achievements
18 Karma
0 Total ProTip Views
Nephila Komaci
Have at least one original repos where PHP is the dominant language
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Got it!
var alertService = {};
$rootScope.alerts = [];
alertService.add = function(type, msg, timeout) {
$rootScope.alerts.push({
type: type,
msg: msg,
close: function() {
return alertService.closeAlert(this);
}
});
// timeout
if (timeout) {
$timeout(function(){
alertService.closeAlert(this);
}, timeout);
}
};
alertService.closeAlert = function(alert) {
return this.closeAlertIdx($rootScope.alerts.indexOf(alert));
};
alertService.closeAlertIdx = function(index) {
return $rootScope.alerts.splice(index, 1);
};
return alertService;