Give a value to an ng-model=”searchText” input based on list item clicked in Angular JS

I think you have a few mistakes in the code:

<div ng-model="chosen">
    <a ng-click="setMaster(cities)" ng-repeat="cities in cities | filter:searchText | limitTo:limit" href="#" class="list-group-item">{{cities}}</a>
</div>

shoud be

<div ng-repeat="city in cities | filter:searchText | limitTo:limit">
    <a ng-click="setMaster(city)" class="list-group-item">{{city}}</a>
</div>

then I think what you want is

$scope.setMaster = function(city) {
    $scope.searchText = city;
}

Also, I’m not sure what the ng-model on the div is for, as far as I know it is used only for inputs, textareas and selects. See http://docs.angularjs.org/api/ng.directive:ngModel.

You probably want something like this fiddle -> http://jsfiddle.net/weSpW/3/.

Leave a Comment