2016-06-27 3 views
0

У меня есть угловой тип bootstrap для малой автозаполнения, и мне нужно вызвать размытие ввода, на которое я применил typehead onSelect of typehead.как вызвать размытие на входе с использованием углового типа head?

HTML код:

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

JS код

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

ответ

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; 
     }; 
    } 
    }; 
});