google-maps-autocomplete icon indicating copy to clipboard operation
google-maps-autocomplete copied to clipboard

When setting 'fields' in 'autoCompleteOptions' if address_components is missing then autocomplete fails with: Cannot read property 'forEach' of undefined

Open tariknz opened this issue 5 years ago • 2 comments

Bug Report or Feature Request (mark with an x)

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

OS and Version?

Windows 10

Versions

Angular CLI: 9.0.2 Node: 12.3.1 OS: win32 x64

Angular: 9.0.1 google-maps-autocomplete: 4.0.1

Repro steps

<input
      matGoogleMapsAutocomplete
      [autoCompleteOptions]="{
         fields: [
           'formatted_address', 'geometry', 'place_id'
         ]
       }"
    />

The log given by the failure

Uncaught TypeError: Cannot read property 'forEach' of undefined

...
place.address_components.forEach(value => { <--- this fails here because address_components is undefined
                        if (value.types.indexOf('street_number') > -1) {
                            germanAddress.streetNumber = value.short_name;
                        }
...

Desired functionality

Ideally it should only run that piece of code when there is an emitter set for onGermanAddressMapped OR it should always include address_components in the fields list. Or maybe a more descriptive message.

Mention any other details that might be useful

Work around for now is just to always include the 'address_components' in the fields list when specifying fields.

tariknz avatar Feb 14 '20 09:02 tariknz

I'm seeing this same error in version 6.2.2

tmjeee avatar Feb 11 '22 10:02 tmjeee

I got maximum stack exceeded on upgrading to the latest version, Is there any workaround without upgrading to the new version.

pratapdev avatar Apr 18 '22 10:04 pratapdev