feat(alert): allow alerts to be closed from a controller

Closes #2399
Closes #2854
This commit is contained in:
Pawel Kozlowski
2014-10-19 20:09:35 +02:00
parent c9baf00762
commit ca6fad675b
2 changed files with 34 additions and 1 deletions
+13 -1
View File
@@ -2,6 +2,7 @@ angular.module('ui.bootstrap.alert', [])
.controller('AlertController', ['$scope', '$attrs', function ($scope, $attrs) {
$scope.closeable = 'close' in $attrs;
this.close = $scope.close;
}])
.directive('alert', function () {
@@ -16,4 +17,15 @@ 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));
}
};
}]);
+21
View File
@@ -0,0 +1,21 @@
describe('dismissOnTimeout', function () {
var scope, $compile, $timeout;
beforeEach(module('ui.bootstrap.alert'));
beforeEach(module('template/alert/alert.html'));
beforeEach(inject(function ($rootScope, _$compile_, _$timeout_) {
scope = $rootScope;
$compile = _$compile_;
$timeout = _$timeout_;
}));
it('should close automatically if auto-dismiss is defined on the element', function () {
scope.removeAlert = jasmine.createSpy();
$compile('<alert close="removeAlert()" dismiss-on-timeout="500">Default alert!</alert>')(scope);
scope.$digest();
$timeout.flush();
expect(scope.removeAlert).toHaveBeenCalled();
});
});