Angular 6 compatible google autocomplete
Demo (original version ng4)
https://tanoy009.github.io/ng4-geoautocomplete/
Test Case.
In Pipeline will be updated in a while.
Table of contents
About
angular 6 compatible google autocomplete with server side api support and AOT enabled
Installation
Install through npm:
npm install --save ngx-geoautocomplete
Then include in your apps module:
import { Component, NgModule } from '@angular/core';
import { NgxGeoautocompleteModule } from 'ngx-geoautocomplete';
@NgModule({
imports: [
NgxGeoautocompleteModule.forRoot()
]
})
export class MyModule {}
Add google place script in your main file generally referred to 'index.html' (Optional if you want to use google services).
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=true&key=XXReplace this with valid keyXX&libraries=places&language=en-US"></script>
Finally use in one of your apps components:
import { Component } from '@angular/core';
@Component({
template: '<ngxgeo-autocomplete [userSettings]="userSettings" (componentCallback)="autoCompleteCallback1($event)"></ng4geo-autocomplete>'
})
export class MyComponent {
userSettings = {}
autoCompleteCallback1(selectedData:any) {
}
}
List of settings that can be used to configure the module (all config. are optional):
{
geoPredictionServerUrl?: string;
geoLatLangServiceUrl?: string;
geoLocDetailServerUrl?: string;
geoCountryRestriction?: any;
geoTypes?: any;
geoLocation?: any;
geoRadius?: number;
serverResponseListHierarchy?: any;
serverResponseatLangHierarchy?: any;
serverResponseDetailHierarchy?: any;
resOnSearchButtonClickOnly?: boolean;
useGoogleGeoApi?: boolean;
inputPlaceholderText?: string;
inputString?: string;
showSearchButton?: boolean;
showRecentSearch?: boolean;
showCurrentLocation?: boolean;
recentStorageName?: string;
noOfRecentSearchSave?: number;
currentLocIconUrl?: string;
searchIconUrl?: string;
locationIconUrl?: string;
}
NOTE: Component settings can also be altered after component initialization. Please follow the below method to change.
this.userSettings: any = {
inputPlaceholderText: 'This is the placeholder text doring component initialization'
}
this.userSettings['inputPlaceholderText'] = 'This is the placeholder text after doing some external operation after some time';
this.userSettings = Object.assign({},this.userSettings)
NOTE:
'geoTypes' can be used for multiple Place Types like ['(regions)', '(cities)']
OR ['(regions)', 'establishment', 'geocode']
. This will make individual api call for each Place Types to google to fetch lists and then it will merge the resuts with uniqueness.To know avalable Place Types please refer Google api.USE THIS FEATURE CAREFULLY
You may also find it useful to view the demo source.
You can change the component css in the below manner (You have to set encapsulation to None)
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'any-component-name',
encapsulation: ViewEncapsulation.None,
template: '<div class="demo"><ng4geo-autocomplete (componentCallback)="autoCompleteCallback1($event)"></ng4geo-autocomplete></div>',
styles: ['
.demo #search_places {
height: 100px;
}
']
})
You can use it with system js as well
'ng4-geoautocomplete': 'npm:ng4-geoautocomplete/bundles/ng4-geoautocomplete.umd.js'
Usage without a module bundler
<script src="node_modules/ng4-geoautocomplete/bundles/ng4-geoautocomplete.umd.js"></script>
<script>
// everything is exported ng4Geoautocomplete namespace
</script>
Documentation
All documentation is auto-generated from the source via compodoc and can be viewed here:
https://tanoy009.github.io/ng4-geoautocomplete/docs/
Development
Prepare your environment
- Install Node.js and NPM
- Install local dev dependencies:
npm install
while current directory is this repo
Development server
Run npm start
to start a development server on port 8000 with auto reload + tests.
Testing
Run npm test
to run tests once or npm run test:watch
to continually run tests.
Release
- Bump the version in package.json (once the module hits 1.0 this will become automatic)
npm run release
License
MIT