ngAutocomplete icon indicating copy to clipboard operation
ngAutocomplete copied to clipboard

$watch for text input change

Open kavuri opened this issue 11 years ago • 3 comments

To keep track of the changes to the Places search in the input box, I am using $watch on the ng-model. In the $watch function, I am assigning the longitude and latitude as:

$scope.map.center.latitude = $scope.mapdetails.geometry['k']; $scope.map.center.longitude = $scope.mapdetails.geometry['A'];

If I do not check on the validity of mapdetails, I get a 'undefined' error. But I realized that even if I select an item from the autocomplete list, I still see that 'mapdetails' is returned as empty. So, I am never able to retrieve the results in the $watch function. What would be the proper way to act after an item is selected from the dropdown autocomplete list? I have tried using ng-change too, but the same result

kavuri avatar May 04 '14 18:05 kavuri

After debugging a bit more, I found that $scope.mapdetails always returns the value of the previous search. So in the first search, mapdetails = undefined and from the next search onwards, it has the value of the previous search. But if I print the values in the html file, they are printed correctly (confused!)

kavuri avatar May 05 '14 12:05 kavuri

If I add a signal once the results are available, and in my controller listen for the signal, I get the results. https://github.com/wpalahnuk/ngAutocomplete/pull/20

If there is a better solution, I would like to use it rather than the signal mechanism

kavuri avatar May 05 '14 12:05 kavuri

Can you try watching the details object instead? I believe the issue is that the ng-model updates any time the text in the input box changes, and the details object only updates when ngAutocomplete actually returns a result

wpalahnuk avatar Jun 18 '14 04:06 wpalahnuk