angularjs - Capture "updater" action from AngularUI's Bootstrap Typeahead -


how can capture "updater" event angularui's ui bootstrap directive?

i've defined html:

<input type="text" pattern="[0-9]*" class="span6" placeholder="8675309" ng-model="empid" typeahead="entry entry in httpempidsearch($viewvalue, 8)"> 

... , associated function:

$scope.httpempidsearch = function(query, limit) {     return $http.get(         '/visitorlog/api/v1/employee/?limit=' + limit + '&empid__startswith=' + query     ).then(function(response)     {         output = [];          angular.foreach(response.data.objects, function(value, key) {             this.push(value.bems.tostring());         }, output);          return output;     }); } 

i take additional action (autocomplete form) when user clicks on id in popup. if raw bootstrap use "updater":

$('#sampleelement').typeahead({   minlength: 3,   source: function (query, process)    {     // data   },   updater: function (item)   {     // user clicked on item, more!   }, }); 

i've tried various listeners like:

$scope.$on('typeahead-updated', function(event) { ... } 

but i've not way let me capture such event. there way can take additional action once typeahead option selected?

it not appear there way hook event in directive. put watch on model value , simulate behavior.

check out plunker example

since pulling list of data server on fly solution may not work you. have @ watch seems best way achieve desired outcome.

something along these lines work.

$scope.output = []; $scope.httpempidsearch = function(query, limit) {     return $http.get(         '/visitorlog/api/v1/employee/?limit=' + limit + '&empid__startswith=' + query     ).then(function(response)     {         $scope.output.length = 0;          angular.foreach(response.data.objects, function(value, key) {             this.push(value.bems.tostring());         }, $scope.output);          return $scope.output;     }); }  $scope.$watch('empid', function(newvalue, oldvalue){     if(newvalue !== oldvalue && $scope.output.indexof(newvalue) !== -1){        //do work here     } }); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -