Skip to content

Commit 800d080

Browse files
committed
fix(timepicker): fix auto-close error with angular 1.3 $animate
timepicker's auto-close test is failing with angularjs 1.3 release. Looks like the error might be solved once angular merges pull request angular/angular.js#9636, which introduces a check to avoid the exception. Anyway, the close on blur test works, so something else is triggering the error. By calling the $timepicker.hide method inside a $timeout when auto-closing, the error goes away, so this seems a good fix.
1 parent e73c186 commit 800d080

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/timepicker/test/timepicker.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
describe('timepicker', function() {
44

5-
var $compile, $templateCache, $animate, $timepicker, dateFilter, scope, sandboxEl, today;
5+
var $compile, $templateCache, $animate, $timepicker, dateFilter, scope, sandboxEl, today, $timeout;
66

77
beforeEach(module('ngAnimate'));
88
beforeEach(module('ngAnimateMock'));
99
beforeEach(module('ngSanitize'));
1010
beforeEach(module('mgcrea.ngStrap.timepicker'));
1111

12-
beforeEach(inject(function (_$rootScope_, _$compile_, _$templateCache_, _$animate_, _$timepicker_, _dateFilter_) {
12+
beforeEach(inject(function (_$rootScope_, _$compile_, _$templateCache_, _$animate_, _$timepicker_, _dateFilter_, _$timeout_) {
1313
scope = _$rootScope_.$new();
1414
sandboxEl = $('<div>').attr('id', 'sandbox').appendTo($('body'));
1515
$compile = _$compile_;
@@ -18,6 +18,7 @@ describe('timepicker', function() {
1818
$timepicker = _$timepicker_;
1919
dateFilter = _dateFilter_;
2020
today = new Date();
21+
$timeout = _$timeout_;
2122
}));
2223

2324
afterEach(function() {
@@ -361,6 +362,7 @@ describe('timepicker', function() {
361362
expect(sandboxEl.children('.dropdown-menu.timepicker').length).toBe(0);
362363
angular.element(elm[0]).triggerHandler('focus');
363364
angular.element(sandboxEl.find('.dropdown-menu tbody .btn:first')).triggerHandler('click');
365+
$timeout.flush();
364366
expect(sandboxEl.children('.dropdown-menu.timepicker').length).toBe(0);
365367
});
366368

src/timepicker/timepicker.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ angular.module('mgcrea.ngStrap.timepicker', ['mgcrea.ngStrap.helpers.dateParser'
3030
arrowBehavior: 'pager'
3131
};
3232

33-
this.$get = function($window, $document, $rootScope, $sce, $locale, dateFilter, $tooltip) {
33+
this.$get = function($window, $document, $rootScope, $sce, $locale, dateFilter, $tooltip, $timeout) {
3434

3535
var bodyEl = angular.element($window.document.body);
3636
var isNative = /(ip(a|o)d|iphone|android)/ig.test($window.navigator.userAgent);
@@ -89,7 +89,7 @@ angular.module('mgcrea.ngStrap.timepicker', ['mgcrea.ngStrap.helpers.dateParser'
8989
controller.$setViewValue(controller.$dateValue);
9090
controller.$render();
9191
if(options.autoclose && !keep) {
92-
$timepicker.hide(true);
92+
$timeout(function() { $timepicker.hide(true); });
9393
}
9494
};
9595

0 commit comments

Comments
 (0)