2016-06-27 12 views
0

Ich habe die eckige bootstrap typehead für kleine Autocomplete und ich muss die Unschärfe des Eingangs auslösen, auf dem ich den typehead onSelect von typehead angewendet habe.Wie triggert man die Unschärfe am Eingang, wenn man die Winkelschrift anwendet?

HTML-Code:

<input class="form-control" ng-model="customItemSelected" typeahead-template-url="customAutoCompleteTemplate.html" 
type="text" typeahead-on-select="onSelect($item)" /> 

JS-Code

$scope.onSelect = function(stateItem){ 
$scope.customItemSelected = ""; 
// trigger the blur of input so that placeholder appear 
} 

Antwort

1

html

<input type="text" ng-model="sales" name="example-input-normal" 
                 typeahead="value.CompanyName for value in Debtors | filter:$viewValue | limitTo:8" typeahead-focus/> 

js

app.directive('typeaheadFocus', function() { 
    return { 
    require: 'ngModel', 
    link: function (scope, element, attr, ngModel) { 

     //trigger the popup on 'click' because 'focus' 
     //is also triggered after the item selection 
     element.bind('click', function() { 

     var viewValue = ngModel.$viewValue; 

     //restore to null value so that the typeahead can detect a change 
     if (ngModel.$viewValue == ' ') { 
      ngModel.$setViewValue(null); 
     } 

     //force trigger the popup 
     ngModel.$setViewValue(' '); 

     //set the actual value in case there was already a value in the input 
     ngModel.$setViewValue(viewValue || ' '); 
     }); 

     //compare function that treats the empty space as a match 
     scope.emptyOrMatch = function (actual, expected) { 
     if (expected == ' ') { 
      return true; 
     } 
     return actual.indexOf(expected) > -1; 
     }; 
    } 
    }; 
});