Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(alert): allow interpolations with dismiss-on-timeout
Browse files Browse the repository at this point in the history
Fixes #4665
Closes #4666
  • Loading branch information
Foxandxss committed Oct 20, 2015
1 parent 563410c commit de24f46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/alert/alert.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
angular.module('ui.bootstrap.alert', [])

.controller('UibAlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) {
.controller('UibAlertController', ['$scope', '$attrs', '$interpolate', '$timeout', function($scope, $attrs, $interpolate, $timeout) {
$scope.closeable = !!$attrs.close;

if (angular.isDefined($attrs.dismissOnTimeout)) {
var dismissOnTimeout = angular.isDefined($attrs.dismissOnTimeout) ?
$interpolate($attrs.dismissOnTimeout)($scope.$parent) : null;

if (dismissOnTimeout) {
$timeout(function() {
$scope.close();
}, parseInt($attrs.dismissOnTimeout, 10));
}, parseInt(dismissOnTimeout, 10));
}
}])

Expand Down
13 changes: 13 additions & 0 deletions src/alert/test/alert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ describe('uib-alert', function() {
$timeout.flush();
expect(scope.removeAlert).toHaveBeenCalled();
});

it('should not close immediately with a dynamic dismiss-on-timeout', function() {
scope.removeAlert = jasmine.createSpy();
scope.dismissTime = 500;
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="{{dismissTime}}">Default alert!</uib-alert>')(scope);
scope.$digest();

$timeout.flush(100);
expect(scope.removeAlert).not.toHaveBeenCalled();

$timeout.flush(500);
expect(scope.removeAlert).toHaveBeenCalled();
});
});

/* Deprecation tests below */
Expand Down

0 comments on commit de24f46

Please sign in to comment.