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

Commit de24f46

Browse files
committed
fix(alert): allow interpolations with dismiss-on-timeout
Fixes #4665 Closes #4666
1 parent 563410c commit de24f46

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/alert/alert.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
angular.module('ui.bootstrap.alert', [])
22

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

6-
if (angular.isDefined($attrs.dismissOnTimeout)) {
6+
var dismissOnTimeout = angular.isDefined($attrs.dismissOnTimeout) ?
7+
$interpolate($attrs.dismissOnTimeout)($scope.$parent) : null;
8+
9+
if (dismissOnTimeout) {
710
$timeout(function() {
811
$scope.close();
9-
}, parseInt($attrs.dismissOnTimeout, 10));
12+
}, parseInt(dismissOnTimeout, 10));
1013
}
1114
}])
1215

src/alert/test/alert.spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ describe('uib-alert', function() {
136136
$timeout.flush();
137137
expect(scope.removeAlert).toHaveBeenCalled();
138138
});
139+
140+
it('should not close immediately with a dynamic dismiss-on-timeout', function() {
141+
scope.removeAlert = jasmine.createSpy();
142+
scope.dismissTime = 500;
143+
$compile('<uib-alert close="removeAlert()" dismiss-on-timeout="{{dismissTime}}">Default alert!</uib-alert>')(scope);
144+
scope.$digest();
145+
146+
$timeout.flush(100);
147+
expect(scope.removeAlert).not.toHaveBeenCalled();
148+
149+
$timeout.flush(500);
150+
expect(scope.removeAlert).toHaveBeenCalled();
151+
});
139152
});
140153

141154
/* Deprecation tests below */

0 commit comments

Comments
 (0)