diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index b69e4d5c9d..016a51c180 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -369,6 +369,29 @@ describe('typeahead tests', function () { expect(inputEl.val()).toEqual('baz'); }); + it('should invoke select callback on select', function () { + + $scope.states = [ + {code: 'AL', name: 'Alaska'}, + {code: 'CL', name: 'California'} + ]; + $scope.onSelect = function ($item, $model, $label) { + $scope.$item = $item; + $scope.$model = $model; + $scope.$label = $label; + }; + var element = prepareInputEl("
"); + var inputEl = findInput(element); + + changeInputValueTo(element, 'Alas'); + triggerKeyDown(element, 13); + + expect($scope.result).toEqual('AL'); + expect($scope.$item).toEqual($scope.states[0]); + expect($scope.$model).toEqual('AL'); + expect($scope.$label).toEqual('Alaska'); + }); + it('should correctly update inputs value on mapping where label is not derived from the model', function () { $scope.states = [{code: 'AL', name: 'Alaska'}, {code: 'CL', name: 'California'}]; diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index a506d4c54a..5ba80e2213 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -50,6 +50,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position']) var isLoadingSetter = $parse(attrs.typeaheadLoading).assign || angular.noop; + var onSelectCallback = $parse(attrs.typeaheadOnSelect); + //pop-up element used to display matches var popUpEl = angular.element( "