Skip to main content

 ERROR Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating 'ce.imageURL')

 

Tools

Platform / package Version
Xcode 13.2.1
Typescript / Angular 6
Cordova  
Capacitor  

 

The code where the error was being generated

if (!this.imageCollection) {
    return baseUrl + req;
}

let image = this.imageCollection.find(obj => obj.fishID === fishId);

if (image.imageURL) {
    return image.imageURL;
} else {
    return baseUrl + req;
}

If you initialize your image attribute as an object instance with no fields.  Then, on component creation: image is never undefined (so the image?.xxx in the template is useless) but image has no imageURL field.  Hence, the reason that you get an error. To fix it declare your attribute as

// ....

if (image?.imageURL) {
    return image.imageURL;
} else {
    return baseUrl + req;
}

 

Related articles

Andrew Fletcher12 Aug 2022
Using SwiftUI URLComponent to change a URL's scheme
The challenge I was facing, I had written a script to scan barcodes and use Google book API to view the contents.  However, a snippet of the JSON response { "contentVersion": "0.2.0.0.preview.0", "panelizationSummary": { "containsEpubBubbles": false, ...