Sampath
Sampath

Reputation: 65930

TypeError: Cannot read property 'ShoppingCart' of undefined at Object.eval

.html

  <div *ngFor="let p of (products$ | async)?.result.categories.ShoppingCart;">
        {{p.price}}
   </div>

.ts

this.products$ = this.bikeShopService.get();

postman

{
    "result": [
        {
            "categories": [
                {
                    "ShoppingCart": [
                        {
                            "id": 1,
                            "name": "Golf Clubs",
                            "price": "125",

}]}]}

ERROR TypeError: Cannot read property 'ShoppingCart' of undefined at Object.eval [as updateDirectives] (BikeShopListPage.html:22) at Object.debugUpdateDirectives [as updateDirectives] (core.js:23813) at checkAndUpdateView (core.js:23209) at callViewAction (core.js:23450) at execComponentViewsAction (core.js:23392) at checkAndUpdateView (core.js:23215) at callViewAction (core.js:23450) at execEmbeddedViewsAction (core.js:23413) at checkAndUpdateView (core.js:23210) at callViewAction (core.js:23450)

Q: Can you tell me how to access the above data?

Upvotes: 0

Views: 1280

Answers (2)

Robert Leeuwerink
Robert Leeuwerink

Reputation: 489

Your items are Arrays, you might want to consider taking out the array part [] or if arrays/lists are needed give the Objects in your array UID's

ngFor can be used in HTML or .map() in a function

Upvotes: 0

dileepkumar jami
dileepkumar jami

Reputation: 2265

It should be .result[0]?.categories[0]?.ShoppingCart

result and categories are arrays and not objects

Upvotes: 1

Related Questions