Nicolas
Nicolas

Reputation: 4756

JavaScript - Can't read property of undefined

Okay, this might be a stupid question, because I'm missing something, but I just can't seem to figure out what!

this is my object, using {{ definitionList | json }}

{
  "State": "Success",
  "Data": [
    {
      "Description": "Default",
      "ID": 4,
    },
    {
      "Description": "Hello World",
      "ID": 14,
    },
    {
      "Description": "Test Def",
      "ID": 11,
    },
    {
      "Description": "test definitie",
      "ID": 12,
    },
    {
      "Description": "testffvfvfvffv",
      "ID": 8,
    },
    {
      "Description": "Werknemer_kantoor",
      "ID": 3,
      "Type": 
    },
    {
      "Description": "Werknemer_kantoor",
      "ID": 6,
    }
  ],
  "Error": null
}

okay now I want to print out "Data" uisng {{ definitionList.Data | json }}

and I receive the error

ORIGINAL EXCEPTION: Cannot read property 'Data' of undefined

I don't understand why? What am I missing?

Upvotes: 2

Views: 177

Answers (1)

AngularChef
AngularChef

Reputation: 14087

Maybe you're loading definitionList asynchronously and it is not yet defined when your template is executed?

Try the following code instead (note the ?):

{{ definitionList?.Data | json }}

Upvotes: 1

Related Questions