@@ -30,7 +30,7 @@ angular.module('ui.bootstrap.typeahead', [])
3030} ] )
3131
3232 //options - min length
33- . directive ( 'typeahead' , [ '$compile' , '$q' , '$document' , 'typeaheadParser' , function ( $compile , $q , $document , typeaheadParser ) {
33+ . directive ( 'typeahead' , [ '$compile' , '$parse' , '$ q', '$document' , 'typeaheadParser' , function ( $compile , $parse , $q , $document , typeaheadParser ) {
3434
3535 var HOT_KEYS = [ 9 , 13 , 27 , 38 , 40 ] ;
3636
@@ -49,6 +49,8 @@ angular.module('ui.bootstrap.typeahead', [])
4949 //should it restrict model values to the ones selected from the popup only?
5050 var isEditable = originalScope . $eval ( attrs . typeaheadEditable ) !== false ;
5151
52+ var isLoadingSetter = $parse ( attrs . typeaheadLoading ) . assign || angular . noop ;
53+
5254 //create a child scope for the typeahead directive so we are not polluting original scope
5355 //with typeahead-specific data (matches, query etc.)
5456 var scope = originalScope . $new ( ) ;
@@ -64,6 +66,7 @@ angular.module('ui.bootstrap.typeahead', [])
6466 var getMatchesAsync = function ( inputValue ) {
6567
6668 var locals = { $viewValue : inputValue } ;
69+ isLoadingSetter ( originalScope , true ) ;
6770 $q . when ( parserResult . source ( scope , locals ) ) . then ( function ( matches ) {
6871
6972 //it might happen that several async queries were in progress if a user were typing fast
@@ -88,8 +91,12 @@ angular.module('ui.bootstrap.typeahead', [])
8891 } else {
8992 resetMatches ( ) ;
9093 }
94+ isLoadingSetter ( originalScope , false ) ;
9195 }
92- } , resetMatches ) ;
96+ } , function ( ) {
97+ resetMatches ( ) ;
98+ isLoadingSetter ( originalScope , false ) ;
99+ } ) ;
93100 } ;
94101
95102 resetMatches ( ) ;
0 commit comments