Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ngx-google-places-autocomplete

skynet269.3kMIT2.0.5TypeScript support: included

This module is a wrapper for Google Places Autocomplete js library.

autocomplete, typescript, google places, angular 5, angular 6, angular 7, angular 2, angular 4, angular

readme

ngx-google-places-autocomplete

This module is a wrapper for Google Places Autocomplete js library.

NPM

Installation

npm

npm install ngx-google-places-autocomplete

yarn

yarn add ngx-google-places-autocomplete

Integration

  1. Add google library in your index.html file :
     <script src="https://maps.googleapis.com/maps/api/js?key=<Your API KEY>&libraries=places&language=en"></script>
  2. Replace <You API KEY> with google places api key. Ref - https://developers.google.com/places/web-service/get-api-key

Usage

  1. Add a module into your application (as a rule app.module.ts) `ts import { GooglePlaceModule } from "ngx-google-places-autocomplete";

@NgModule({ imports: [GooglePlaceModule, BrowserModule, FormsModule, ...], .... })

2. Add directive ngx-google-places-autocomplete to your input field (options is an optional parammeter)

<input ngx-google-places-autocomplete [options]='options' #placesRef="ngx-places" (onAddressChange)="handleAddressChange($event)"/>

3. Additionally you can reference directive in your component
```ts
    @ViewChild("placesRef") placesRef : GooglePlaceDirective;

        public handleAddressChange(address: Address) {
        // Do some stuff
    }

Angular Universal

In order to use under angular universal please check that comment https://github.com/skynet2/ngx-google-places-autocomplete/issues/15#issuecomment-465371214

Options

Refer to original google maps api - https://developers.google.com/maps/documentation/javascript/places-autocomplete Options object - https://github.com/skynet2/ngx-google-places-autocomplete/blob/master/src/objects/options/options.ts Google doc for Options : https://developers.google.com/maps/documentation/javascript/reference/places-widget#AutocompleteOptions Example :

[options]="{
    types: [],
    componentRestrictions: { country: 'UA' }
    }"

GitHub

Please feel free to declare issues or contribute: https://github.com/skynet2/ngx-google-places-autocomplete

changelog

2.0.5 (2020-03-11)

Bug Fixes

  • Place should be returned even if place_id is missing when selecting specific fields (#47)
  • Add origin field to Google Autocomplete constructor option type (#51)

2.0.4 (2019-06-02)

Bug Fixes

  • Early-exit if no keydown event key exists (#35)
  • Added fields property (#36)

2.0.3 (2018-12-11)

Bug Fixes

  • Form Submission on Enter (#17)
  • Not able to get photo_reference (#18)
  • Click is not working in iOS 9 (#22)

2.0.2 (2018-12-11)

Bug Fixes

  • Duplicated dropdown (#13)