File

packages/location/src/lib/location-search.component.ts

Description

Google Maps Location Searchbar

Implements

AfterViewInit

Metadata

selector ec-location-search
templateUrl ./location-search.component.html

Index

Properties
Methods
Inputs
Outputs

Constructor

constructor(geocodeService: GeocodeService)
Parameters :
Name Type Optional
geocodeService GeocodeService No

Inputs

disabled

If true, the input cannot be used

placeholder
Default value : 'Search Location...'

Placeholder for input

Outputs

changed
Type : EventEmitter<any>

emits when the coords have been changed (after selecting a match)

Methods

clear
clear()

Clears the searchbar input value

Returns : void
ngAfterViewInit
ngAfterViewInit()

subscribes to changes from the inputs autocomplete using geocodeService.

Returns : void

Properties

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"
/>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""