Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 嵌套的NgFor不工作-角度2_Javascript_Angular_Angular2 Template - Fatal编程技术网

Javascript 嵌套的NgFor不工作-角度2

Javascript 嵌套的NgFor不工作-角度2,javascript,angular,angular2-template,Javascript,Angular,Angular2 Template,我正在尝试将AngularJS应用程序转换为Angular2应用程序。我的模板中有一个嵌套循环。但当我使用Angular2语法时,它不起作用 这是我的密码- <table> <tr *ngFor = "let lbusQuestionAnswer of ibusQuestion.ilstQuestionAnswer"> <table> <tr *ngFor = "let lbusComment of lbusQuestionAnswer.i

我正在尝试将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>
我知道,在StackOverflow上有很多类似的问题。但似乎一切都不起作用

谢谢 法哈德·穆拉吉


<div *ngIf="ibusQuestion && lbusQuestionAnswer" >
  <table>
    ...
  </table>
</div>
...
在vista中的mostrarlos存在元素的有效性


...

我在这里找到了解决这个问题的方法-

当我添加
时,它工作得很好


我希望这个答案能帮助并解释它背后的真正原因

我在这里找到了解决办法-

当我添加
时,它工作得很好


我希望这个答案有助于解释它背后的真正原因

您的例外意味着
lbusquestionsweal
未定义的
,但它不是。让我在问题中添加可能的JSON我知道它没有定义,但为什么它没有定义,当它应该有值时,它应该有值。我建议您尝试将
ibusQuestion.ilstQuestionAnswer
记录到控制台,或在您的视图中呈现它,以检查数据是否确实如您所期望的那样存在。但从技术上讲,如果ibusQuestion.ilstQuestionAnswer没有值,则它甚至不应该进入嵌套循环。它肯定会失败。您的异常意味着
lbusQuestionAnswer
未定义的
,但它不是。让我在问题中添加可能的JSON我知道它没有定义,但为什么它没有定义,当它应该有值时,它应该有值。我建议您尝试将
ibusQuestion.ilstQuestionAnswer
记录到控制台,或在您的视图中呈现它,以检查数据是否确实如您所期望的那样存在。但从技术上讲,如果ibusQuestion.ilstQuestionAnswer没有值,则它甚至不应该进入嵌套循环。它肯定会失败。
<div *ngIf="ibusQuestion && lbusQuestionAnswer" >
  <table>
    ...
  </table>
</div>