Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent extractValue from blowing up on undefined #477

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Prevent extractValue from blowing up on undefined #477

wants to merge 1 commit into from

Conversation

clov3r
Copy link

@clov3r clov3r commented Mar 11, 2017

Given that angucomplete-alt supports passing a . separated key in image-field (and other fields), this fix will prevent an error in the case of an undefined value.

That is, given:

let data = [{
    // ...
    id: 1,
    logo: undefined,
    // ...
} , {
    // ...
    id: 2,
    logo: {
        thumbnail: '/img/users/portrait.png'}
    }
}]

and passing image-field="logo.thumbnail" local-data="data" to angucomplete-alt, this currently causes an error on the first item: TypeError: Cannot read property 'thumbnail' of undefined, and no further items are rendered in the autocomplete dropdown.

This PR just adds a check to see if the current value exists before attempting to access the property.

Came across this in the course of work, just thought I'd submit this fix for you (worked around it locally). Let me know if you need me to do more to improve the PR, but it seems fairly trivial.

Regards,
Callum

Given that angucomplete-alt supports passing a `.` separated key in `image-field` (and other fields), this fix will prevent an error in the case of an undefined value.

That is, given:
```
let data = [{
    // ...
    id: 1,
    logo: undefined,
    // ...
} , {
    // ...
    id: 2,
    logo: {
        thumbnail: '/img/users/portrait.png'}
    }
}]
```
and passing `image-field="logo.thumbnail" local-data="data"` to angucomplete-alt, this currently causes an error on the first item: `TypeError: Cannot read property 'thumbnail' of undefined`, and no further items are rendered in the autocomplete dropdown.

This PR just adds a check to see if the current value exists before attempting to access the property.

Came across this in the course of work, just thought I'd submit this fix for you (worked around it locally). Let me know if you need me to do more to improve the PR, but it seems fairly trivial.

Regards, 
Callum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant