Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Created January 10, 2016 20:04
Show Gist options
  • Save auxcoder/ae867b8d2fee306516cd to your computer and use it in GitHub Desktop.
Save auxcoder/ae867b8d2fee306516cd to your computer and use it in GitHub Desktop.
Google Autocomplete Address Places
(function() {
'use strict';
angular
.module('myApp')
.directive('googlePlaces', googlePlaces);
/** @ngInject */
function googlePlaces(){
return {
restrict:'A',
scope: false,
link: function($scope, element){
var options = {
types: ['geocode'],
componentRestrictions: {country: 'us'}
};
var location = new google.maps.places.Autocomplete(element[0], options);
google.maps.event.addListener(location, 'place_changed',
function() {
var place = location.getPlace();
$scope.address = place.address_components;
$scope.$apply();
}
);
}
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment