【发布时间】:2017-01-11 15:09:36
【问题描述】:
我正在尝试将我的 AngularJS 应用程序转换为 Angular2 应用程序。我的模板中有一个嵌套循环。但是当我使用 Angular2 语法时它不起作用。
这是我的代码 -
<table>
<tr *ngFor = "let lbusQuestionAnswer of ibusQuestion.ilstQuestionAnswer">
<table>
<tr *ngFor = "let lbusComment of lbusQuestionAnswer.ilstComments">
<td>
<div>{{lbusComment.icdoComment.idoComment.commentHtml}}</div>
</td>
</tr>
</table>
</tr>
</table>
EXCEPTION: TypeError: Cannot read property 'ilstComments' of undefined
我知道,在 StackOverflow 上有很多类似的问题。但似乎没有任何效果。
谢谢 法赫德·穆拉吉
【问题讨论】:
-
您的异常意味着
lbusQuestionAnswer是undefined -
但事实并非如此。让我在问题中添加可能的 JSON
-
我知道它是未定义的,但为什么它是未定义的,什么时候应该有值
-
它应该有值。我建议您尝试将
ibusQuestion.ilstQuestionAnswer记录到控制台或将其呈现在您的视图中以检查数据是否确实如您所愿。 -
但从技术上讲,如果 ibusQuestion.ilstQuestionAnswer 没有值,那么它甚至不应该进入嵌套循环。它肯定会失败。
标签: javascript angular angular2-template