无法读取未定义的属性“ empId”

时间:2019-07-15 09:05:05

标签: angular7

以下是响应(Json):

{
    "formId": 2,
    "empId": {
        "empEmail": "abc@gmail.com",
        "empName": "John",
        "empId": "1234",
        "role": 3
    },
    "skillClass": "UI",
    "fromDate": "2019-07-18T18:30:00.000+0000",
    "toDate": "2019-07-26T18:30:00.000+0000",
    "status": "open",
    "userComments": "ee3de3",
    "allocatedHours": 0,
    "comments": null
}

TS。文件是:

data = {};
this.data = reponse;

和HTML:

 input type="text" [(ngModel)]="data.empId.empId"  disabled name="empId" minlength="4" #empId="ngModel"  class="form-control" required

但是我得到一个错误:

  

无法读取未定义的属性'empId'

如何摆脱此错误?

1 个答案:

答案 0 :(得分:0)

尽管这个问题似乎有点不完整,但看起来您有错字:

this.data = reponse;

应该是:

this.data = response;