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

fix(alert): allow interpolations with dismiss-on-timeout #4666

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use $scope.$parent.$eval? Is there something superior with interpolation here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That won't work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, PR LGTM then


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