ngAutocomplete
ngAutocomplete copied to clipboard
$watch for text input change
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
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!)
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
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