JavaScript - 无法读取未定义的属性

标签 javascript json angular object

好吧,这可能是一个愚蠢的问题,因为我遗漏了一些东西,但我似乎无法弄清楚是什么!

这是我的对象,使用 {{ 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
}

好的,现在我想打印出“数据” uisng {{ definitionList.Data | json }}

然后我收到错误

ORIGINAL EXCEPTION: Cannot read property 'Data' of undefined

我不明白为什么?我错过了什么?

最佳答案

也许您正在异步加载 definitionList 并且在执行模板时它尚未定义?

尝试使用以下代码(注意 ?):

{{ definitionList?.Data | json }}

关于JavaScript - 无法读取未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42278104/

相关文章:

JavaScript/jQuery 和 "top-level"函数

arrays - NodeJS & Mongoose : Add element to existing empty array

Python - SimpleJSON 问题

javascript - 错误 : Expression 'undefined' used with directive is non-assignable

node.js - 使用 NPM 在 Ubuntu 上全局安装 Electron

javascript - W/网络核心(2733): Can't get the viewWidth after the first layout

JavaScript - 获取具有多个值的元素

javascript - 在 react 中的元素上使用 aria 属性

Angular 2 - @Input 不更新的嵌套组件

java - JSP 向 Angular 6+ UI 提供信息