diff --git a/src/alert/alert.js b/src/alert/alert.js index 3bb79c4437..23d3aa592f 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -1,8 +1,13 @@ angular.module('ui.bootstrap.alert', []) -.controller('AlertController', ['$scope', '$attrs', function($scope, $attrs) { +.controller('AlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) { $scope.closeable = !!$attrs.close; - this.close = $scope.close; + + if (angular.isDefined($attrs.dismissOnTimeout)) { + $timeout(function() { + $scope.close(); + }, parseInt($attrs.dismissOnTimeout, 10)); + } }]) .directive('alert', function() { @@ -19,15 +24,4 @@ angular.module('ui.bootstrap.alert', []) close: '&' } }; -}) - -.directive('dismissOnTimeout', ['$timeout', function($timeout) { - return { - require: 'alert', - link: function(scope, element, attrs, alertCtrl) { - $timeout(function() { - alertCtrl.close(); - }, parseInt(attrs.dismissOnTimeout, 10)); - } - }; -}]); +}); diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 74514565fc..7f87de81da 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -1,14 +1,14 @@ describe('alert', function() { - var scope, $compile, $templateCache; - var element; + var element, scope, $compile, $templateCache, $timeout; beforeEach(module('ui.bootstrap.alert')); beforeEach(module('template/alert/alert.html')); - beforeEach(inject(function($rootScope, _$compile_, _$templateCache_) { + beforeEach(inject(function($rootScope, _$compile_, _$templateCache_, _$timeout_) { scope = $rootScope; $compile = _$compile_; $templateCache = _$templateCache_; + $timeout = _$timeout_; element = angular.element( '