The best you can do is to write simple reusable directive. Here is a quick basic implementation:
app.directive('inputDropdown', function($compile) {
var template =
'<input ng-model="ngModel">' +
'<div class="dropdown">' +
'<div ng-repeat="value in list">' +
'<div ng-mousedown="select($event, value)">{{value}}</div>' +
'</div>' +
'</div>';
return {
restrict: 'EA',
scope: {
ngModel: '=',
list: '=',
onSelect: '&'
},
template: template,
link: function(scope, element, attrs) {
element.addClass('input-dropdown');
scope.select = function(e, value) {
scope.ngModel = value;
scope.onSelect({$event: e, value: value});
};
}
};
});
Show/hide behaviour would be controlled by CSS :focus pseudo-class:
.input-dropdown {
position: relative;
display: inline-block;
}
.input-dropdown .dropdown {
display: none;
position: absolute;
top: 100%;
left: 0;
width: 100%;
margin-top: 2px;
background: #EEE;
}
.input-dropdown .dropdown div {
cursor: pointer;
padding: 2px 5px;
}
.input-dropdown input:focus + .dropdown {
display: block;
}
And here is a usage:
<input-dropdown ng-model="preference" list="values" on-select="pick(value)"></input-dropdown>
Demo: http://plnkr.co/edit/v1o3fH2vfU9acBSagVZI?p=preview
<input type="text">textbox and a collection of strings which i want to show like drop down list upon focusing on textbox thats it