Skip to content

gao234/angular-google-places-autocomplete

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-google-places-autocomplete

Angular directive for the Google Places Autocomplete component.

Installation

Install via bower: bower install angular-google-places-autocomplete-callback

Or if you're old skool, copy src/autocomplete.js into your project.

Then add the script to your page (be sure to include the Google Places API as well):

<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<script src="/bower_components/angular-google-places-autocomplete/src/autocomplete.js"></script>

You'll probably also want the styles:

<link rel="stylesheet" href="/bower_components/angular-google-places-autocomplete/src/autocomplete.css">

Usage

First add the dependency to your app:

angular.module('myApp', ['google.places']);

Then you can use the directive on text inputs like so:

<input type="text" g-places-autocomplete ng-model="myScopeVar" />

The directive also supports the following optional attributes:

**The original directive fires an event called "g-places-autocomplete:select" with the prediction as parameter. My patch adds the possibility to add a callback when that event is fired, ie: when a new place is selected. To use it, just add an attribute: on-place-updated="myCallback(prediction)" to your directive. In your controller, define $scope.myCallback(place). That function will be called every time a new place is selected from the directive.

eg.

html:

<input type="text" name="address" on-place-updated="vm.googlePlaceComponentsFilter(place)"  ng-model="vm.contact.addresses[0].address_line_1" g-places-autocomplete/>

controller:

        vm.googlePlaceComponentsFilter = googlePlaceComponentsFilter;
        function googlePlaceComponentsFilter(place){
            //do whatever you want to do with place data.
            console.log(place);
        }

Examples

Issues or feature requests

Create a ticket here

Contributing

Issue a pull request including any relevant testing and updated any documentation if required.

About

Pure AngularJS directive for Google Places Autocomplete

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 71.6%
  • HTML 23.5%
  • CSS 4.9%