angular-material-extensions / google-maps-autocomplete

Autocomplete input component and directive for google-maps built with angular and material design |
https://angular-material-extensions.github.io/google-maps-autocomplete
MIT License
169 stars 60 forks source link

Does not emit value changes with reactive forms #317

Closed seanlawrenz closed 3 years ago

seanlawrenz commented 3 years ago

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

OS and Version?

Looks to be any

Versions

Regression started on 4.0

Repro steps

https://stackblitz.com/edit/angular-qxw1kd?file=src/app/app.module.ts

The log given by the failure

No failure. Just does not console log the change in input.

Desired functionality

I should be able to subscribe to changes to the input.

Mention any other details that might be useful

seanlawrenz commented 3 years ago

I see. After 4.0.0 this started using NG_VALUE_ACCESSOR. We're getting the valueChanges for free. onChange would be the event to listen to, but it's buggy as well.

If I'm reading this right the magic is in the new google.maps.places.Autocomplete(this.elemRef.nativeElement, this.autoCompleteOptions);. Not much to go on there. What if we added a HostListener?

@HostListener('input', ['$event'])
  onInputChange(e) {
    this.onChange.emit(e.target.value)
  }

I don't know the downstream implications from this.

AnthonyNahas commented 3 years ago

In that way you will get only the value of the input as string and not as object...

AnthonyNahas commented 3 years ago

I will close this ticket for the momemnt.

Please do not hesitate to reopen this issue if you still facing some problems