I use this directive. However, on the setAddress event output, no changes are detected in my component. The view is not updated. I d'ont understand.
For test, if i remove the google.maps.event.addListener to replace by a simple setTimeout to call invokeEvent. It works.
@Directive({
selector: '[googleplace]',
providers: [NgModel],
host: {
'(input)' : 'onInputChange()'
}
})
export class GoogleplaceDirective {
@Output() setAddress: EventEmitter<any> = new EventEmitter();
modelValue:any;
autocomplete:any;
private _el:HTMLElement;
constructor(el: ElementRef,private model:NgModel) {
this._el = el.nativeElement;
this.modelValue = this.model;
var input = this._el;
this.autocomplete = new google.maps.places.Autocomplete(input, {});
google.maps.event.addListener(this.autocomplete, 'place_changed', ()=> {
var place = this.autocomplete.getPlace();
this.invokeEvent(place);
});
}
invokeEvent(place:Object) {
this.setAddress.emit(place);
}
onInputChange() {
}
}
In my component view
<input type="text" class="validation-address-input" style="margin-top: 100px;" [value]="form.customerAddress"
(setAddress)="setCustomStartLocation($event)" googleplace>
In my component
/**
*
* @param place
*/
setCustomStartLocation(place: Object) {
this.currentStep = 2;
}