Skip to content

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

@tariknz

Description

@tariknz

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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions