diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index 59f3f661aa..1561361ee6 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -575,6 +575,23 @@ describe('typeahead tests', function () { expect(element).toBeOpenWithActive(2, 0); }); + + it('issue #1773 - should not trigger an error when used with ng-focus', function () { + + var element = prepareInputEl('
'); + var inputEl = findInput(element); + + // Note that this bug can only be found when element is in the document + $document.find('body').append(element); + // Extra teardown for this spec + this.after(function () { element.remove(); }); + + changeInputValueTo(element, 'b'); + var match = $(findMatches(element)[1]).find('a')[0]; + + $(match).click(); + $scope.$digest(); + }); }); describe('input formatting', function () { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index 7148ce3031..123d28bc09 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -233,7 +233,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap resetMatches(); //return focus to the input element if a mach was selected via a mouse click event - element[0].focus(); + // use timeout to avoid $rootScope:inprog error + $timeout(function() { element[0].focus(); }, 0, false); }; //bind keyboard events: arrows up(38) / down(40), enter(13) and tab(9), esc(27)