ngAutocomplete icon indicating copy to clipboard operation
ngAutocomplete copied to clipboard

Doesn't have an option to use "submit" button

Open henrihietala opened this issue 11 years ago • 4 comments

This should have an option to use a submit button which would do exactly the same as pressing enter.

If there's a way to simulate enter key, please let me know!

henrihietala avatar Aug 05 '14 13:08 henrihietala

I ended up doing this in parent controller:

var autocompleteService = new google.maps.places.AutocompleteService();

$scope.getPlace = function () {
  if ($scope.autocomplete)
    autocompleteService.getPlacePredictions({
      input: $scope.autocomplete,
      types: ['geocode'],
      componentRestrictions: { country: 'fi' }
    }, callback);
};

function callback(predictions, status) {
  if (status != google.maps.places.PlacesServiceStatus.OK) {
    alert(status);
    return;
  }
  var googlePlacesService = new google.maps.places.PlacesService(document.getElementById("autocomplete"));
  googlePlacesService.getDetails({
    reference: predictions[0].reference
  }, function (details, status) {
    if (details) {
      $scope.addressDetails = details;
      $scope.centerMap();
    }
  });
}

centerMap() contains logic to set the formatted_address to my input field and centering the map.

henrihietala avatar Aug 22 '14 09:08 henrihietala

+1

gogson avatar Sep 15 '14 09:09 gogson

@henrihietala your trick works but I needed to add a $scope.$apply(); in the googlePlacesService.getDetails() callback function.

gogson avatar Sep 15 '14 10:09 gogson

+1

solidevolution avatar Jan 13 '16 11:01 solidevolution