Mirko Mirko - 4 months ago 65x
AngularJS Question

How can I close a bootstrap alert after a specific time using angular.js?

I've a bootstrap alert that appears after some operation is completed,but I want it to close after two or more seconds,how can I achieve this effect?I'm using Angular.js and I've only found solutions in jQuery.


Angular bootstrap provides an option for alert directive dismiss-on-timeout. It accepts timeout in milliseconds. This attribute requires the presence of the close attribute.


<div ng-controller="AlertDemoCtrl">
  <uib-alert type="danger" close="closeAlert()" dismiss-on-timeout="1000">Oh snap! Change a few things up and try submitting again.'</uib-alert>

The JavaScript

angular.module('AlertDemo').controller('AlertDemoCtrl', function ($scope) {

  $scope.closeAlert = function() {
    //close callback