packages/location/src/lib/location-search.component.ts
Google Maps Location Searchbar
selector | ec-location-search |
templateUrl | ./location-search.component.html |
Properties |
Methods |
Inputs |
Outputs |
constructor(geocodeService: GeocodeService)
|
||||||
Parameters :
|
disabled | |
If true, the input cannot be used |
placeholder | |
Default value : 'Search Location...'
|
|
Placeholder for input |
changed | |
Type : EventEmitter<any>
|
|
emits when the coords have been changed (after selecting a match) |
clear |
clear()
|
Clears the searchbar input value
Returns :
void
|
ngAfterViewInit |
ngAfterViewInit()
|
subscribes to changes from the inputs autocomplete using geocodeService.
Returns :
void
|
searchInput |
Type : ElementRef
|
Decorators :
@ViewChild('search', {static: true})
|
The search input element |
import { AfterViewInit, Component, ElementRef, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { } from 'googlemaps';
import { GeocodeService } from './geocode.service';
/** Google Maps Location Searchbar */
@Component({
selector: 'ec-location-search',
templateUrl: './location-search.component.html',
})
export class LocationSearchComponent implements AfterViewInit {
/** Placeholder for input */
@Input() placeholder = 'Search Location...';
/** If true, the input cannot be used */
@Input() disabled;
/** The search input element */
@ViewChild('search', { static: true }) searchInput: ElementRef;
/** emits when the coords have been changed (after selecting a match) */
@Output() changed: EventEmitter<any> = new EventEmitter();
constructor(private geocodeService: GeocodeService) {}
/** Clears the searchbar input value */
clear() {
if (this.searchInput) {
this.searchInput.nativeElement.value = '';
}
}
/** subscribes to changes from the inputs autocomplete using geocodeService. */
ngAfterViewInit() {
this.geocodeService.autocompleteAddress(this.searchInput.nativeElement).subscribe((coords) => {
this.changed.emit(coords);
});
}
}
<input
class="input"
#search
[placeholder]="placeholder"
autocorrect="off"
autocapitalize="off"
spellcheck="off"
type="text"
[disabled]="disabled"
/>