I have a controller in AngularJS and a view which goal is to create an auto-complete dropdown. I have some issues with the functionality. I start typing and the options show under the input but I want to click on one of them and the input's value to change and the suggestions' list to disappear. This is not happening at the moment.
This is my controller:
$http.get(API_URL + "get/cities")
.then(function (response) {
$scope.cities = response.data;
},
function () {
console.log('error');
});
$scope.selectCity = function (cityId, name) {
$scope.citySearch = name;
$scope.showCityList = false;
};
And here is the view:
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<input type="text" ng-model="citySearch" ng-change="showCityList = true" class="form-control input-lg" placeholder="Град">
<ul ng-if="citySearch.length > 0 && showCityList" class="list-group">
<li ng-repeat="city in cities | filter: citySearch | orderBy:'name'" class="list-group-item" ng-click="selectCity(city.id, city.name)">@{{ city.name }}</li>
</ul>
</div>
</div>
</div>
I should mention that this HTML code is placed inside of a ng-switch-when.
doesn't disappear
– dinkogosp Aug 13 '18 at 08:10