I am using Angular JS - ui.bootstrap.typeahead:
I would like to click a button and focus an input field and automatically show the typeahead suggestion dropdown. I h
I got solved this issue through a directive. When you uses this directive, shows the list without some filter then, you type your search to find an element.
angular.module('myapp')
.directive('typeaheadLikeSelect',
['$parse',function($parse) {
return {
require: 'ngModel',
link: function (scope, element, attr, ngModel){
var aux_modelValue, aux_viewValue,
modelGetter = $parse(attr.ngModel),
modelSetter = modelGetter.assign;
var noViewValue = function(){
return
ngModel.$$lastCommittedViewValue === undefined ||
!ngModel.$$lastCommittedViewValue.trim();
};
var forceEvent = function(){
ngModel.$setViewValue();
ngModel.$viewValue = ' ';
ngModel.$setViewValue(' ');
ngModel.$render();
scope.$apply();
element.val(element.val().trim());
};
element.on('mousedown', function(e){
e.stopPropagation();
forceEvent();
});
element.on('blur', function(e){
e.stopPropagation();
if(aux_modelValue){
modelSetter(scope, aux_modelValue);
scope.$apply();
}
});
scope.$watch(function () {
return ngModel.$modelValue;
}, function(newValue, oldValue){
if(newValue || (!newValue && !oldValue))
aux_modelValue = newValue;
});
}
};
}]);
I leave a view code, to testing the above code.
No Results Found