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;
}