Can't access [object Object]

I’m trying to access what word be in version {{order.contact.full_name}} <- this gives me and error, and if I do {{order.contact}} I get [object Object]. If I iterate through the array accommodation_bookings, I can access all objects like contact through there. Anyone have any ideas. Version 1 used to handle it ok!

This is so vague that it’s virtually useless. Post the actual error (as text, not screenshots), as well as the controller code that populates “order”.

1 Like
{
  "id": 2237,
  "full_order_number": "CP-1011",
  "status": "Fully Paid",
  "deposit_percentage": 30,
  "arrival_date": "2018-07-05",
  "departure_date": "2018-07-12",
  "accommodation_total": 2300.0,
  "extras_total": 0.0,
  "total": 2300.0,
  "total_outstanding": 0.0,
  "slug": "3j3yvdegbqb0haqckuu-6q",
  "contact": {
    "first_name": "Clea",
    "last_name": "Yukhov",
    "full_name": "Clea Yukhov",
    "slug": "z5axsjwztuhmymibxivlwq"
  },
  "trading_company": {
    "name": "Chalet Planner France",
    "currency": "€"
  },
  "accommodation_bookings": [
    {
      "accommodation_booking": {
        "arrival_date": "2018-07-05",
        "departure_date": "2018-07-12",
        "price": 2300.0,
        "notes": "",
        "slug": "htzqf8rbvj24c2e1w-yvew",
        "accommodation": {
          "name": "Chalet Planner Chalet",
          "slug": "wmuvhxwt9tmqezf9c2b9sw"
        }
      }
    }
  ],
  "extras": [],
  "payments": [
    {
      "payment": {
        "payment_amount": 2300.0,
        "payment_made": "2018-06-15",
        "contact": {
          "full_name_reverse": "YUKHOV, Clea",
          "slug": "z5axsjwztuhmymibxivlwq"
        }
      }
    }
  ],
  "associated_orders": []
}

I should be able to pull order.contact.full_name but get the error below, and the same for anything in contact

Error: Uncaught (in promise): TypeError: undefined is not an object (evaluating ‘_co.order.contact.full_name’) checkAndUpdateView@http://localhost:8100/build/vendor.js:14223:28 callViewAction@http://localhost:8100/build/vendor.js:14569:39 execComponentViewsAction@http://localhost:8100/build/vendor.js:14501:27 checkAndUpdateView@http://localhost:8100/build/vendor.js:14224:29 callWithDebugContext@http://localhost:8100/build/vendor.js:15472:47 detectChanges@http://localhost:8100/build/vendor.js:11993:40 _viewAttachToDOM@http://localhost:8100/build/vendor.js:52084:53 _transition@http://localhost:8100/build/vendor.js:52164:34 onInvoke@http://localhost:8100/build/vendor.js:5134:39 run@http://localhost:8100/build/polyfills.js:3:10149 http://localhost:8100/build/polyfills.js:3:20245 onInvokeTask@http://localhost:8100/build/vendor.js:5125:43 runTask@http://localhost:8100/build/polyfills.js:3:10844 o@http://localhost:8100/build/polyfills.js:3:7901 invokeTask@http://localhost:8100/build/polyfills.js:3:16824 p@http://localhost:8100/build/polyfills.js:2:27654 v@http://localhost:8100/build/polyfills.js:2:27894

You still haven’t posted the controller code that populates “order”. Presumably it looks something like this:

order: any;

ionViewWillEnter() {
  this.http.get(url).subscribe(o => this.order = o);
}

Any object or array properties that are referenced from templates should be initialized at the point of declaration, even if it is to something mundane like {} or []. In your case, you need to at least get contact also defined in there.