Skip to content

Commit

Permalink
feat(package): added address validator's form control to 'matGoogleMa…
Browse files Browse the repository at this point in the history
…psAutocomplete'
  • Loading branch information
AnthonyNahas committed Sep 4, 2018
1 parent 0f0b8f6 commit 859c103
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/module/directives/mat-google-maps-autocomplete.directive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {Directive, ElementRef, EventEmitter, Input, NgZone, OnInit, Output} from '@angular/core';
import {FormControl, Validators} from '@angular/forms';
import {MatValidateAddressDirective} from '../directives/address-validator/mat-address-validator.directive';
import {MapsAPILoader} from '@agm/core';
import {Location} from '../interfaces/location.interface';
import PlaceResult = google.maps.places.PlaceResult;
import AutocompleteOptions = google.maps.places.AutocompleteOptions;

@Directive({
selector: '[matGoogleMapsAutocomplete]',
exportAs: '[matGoogleMapsAutocomplete]',
exportAs: 'matGoogleMapsAutocomplete',
})
export class MatGoogleMapsAutocompleteDirective implements OnInit {

Expand Down Expand Up @@ -40,12 +42,21 @@ export class MatGoogleMapsAutocompleteDirective implements OnInit {
@Output()
onLocationSelected: EventEmitter<Location> = new EventEmitter<Location>();

private onNewPlaceResult: EventEmitter<any> = new EventEmitter();
private addressValidator: MatValidateAddressDirective = new MatValidateAddressDirective();

public addressSearchControl: FormControl = new FormControl({value: null}, Validators.compose([
Validators.required,
this.addressValidator.validate()])
);

constructor(public elemRef: ElementRef,
public mapsAPILoader: MapsAPILoader,
private _ngZone: NgZone) {
}

ngOnInit(): void {
this.addressValidator.subscribe(this.onNewPlaceResult);
const options = {
// types: ['address'],
componentRestrictions: {country: this.country},
Expand Down

0 comments on commit 859c103

Please sign in to comment.