Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Prevent extractValue from blowing up on undefined#477

Open
clov3r wants to merge 1 commit into
ghiden:masterfrom
clov3r:patch-1
Open

Prevent extractValue from blowing up on undefined#477
clov3r wants to merge 1 commit into
ghiden:masterfrom
clov3r:patch-1

Conversation

@clov3r

@clov3r clov3r commented Mar 11, 2017

Copy link
Copy Markdown

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant