V
V
Vitaly2015-07-15 16:00:02
Angular
Vitaly, 2015-07-15 16:00:02

How to dynamically change ng-model values?

I'm trying to make a simple autocoplete, maybe not quite right but ....
here is my html code:

<input type="search" placeholder="Search" ng-model="stationSearch">
 <button class="button" ng-click="setStation(bn.name)" ng-repeat="bn in itemsList | filter:stationSearch">
              {{bn.name}}
          </button>

and controller code:
$scope.stationSearch = '';
 $scope.setStation = function(bnn){
            $scope.stationSearch = '';
            $scope.stationSearch = bnn;
};
    $scope.itemsList = [
            {'name': 'Iapetos Baltazar', 'amount': 1},
            {'name': 'Mordred Maui', 'amount': 4},
            {'name': 'Verethragna Tane', 'amount': 20},
            {'name': 'Arawn Lir', 'amount': 7},
            {'name': 'Cepheus Zephyrus', 'amount': 15},
            {'name': 'Leander Pallas', 'amount': 9},
            {'name': 'Chryses Vohu Manah', 'amount': 13},
            {'name': 'Nuadha Lycus', 'amount': 19}
        ];

When I click on the button from ng-repeat, the stationSearch variable gets the desired value, so the input field is filled and the filter is triggered.
But if you later delete the data from the inputa or enter data manually at the beginning, then nothing happens when you click on the button from ng-repeat :( input is not filled :(
When checking through console.log, you can see that the stationSearch variable receives a new value, the function click works, but there is no result in the browser

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaliy, 2015-07-16
@Scorpiored88

My problem was solved after I made "stationSearch" object

$scope.stationSearch = {}
and
ng-model="stationSearch.val"

But now a new problem has emerged.
My array "itemsLis" has about 2000 (2 yew) object elements, and when typing letters, there is a rather large delay :(
Can someone tell me how to change my filter so that it works without brakes.
Or maybe there are already good ready-made autocompete solutions that work with a large array of data (
although you probably need to create a new question)

S
Sergey Pashkevich, 2015-07-30
@siarheipashkevich

If still relevant:
ngAutocomplete
angucomplete

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question