Angular2在循环中呈现2个tr元素的组件 [英] Angular2 Component which renders 2 tr elements in a loop

查看:604
本文介绍了Angular2在循环中呈现2个tr元素的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < tr> ...< p< p>< ; / TR> 
< tr> ...< / tr>

必须使用* ngFor来创建表。
组件的选择器是 spot-row
该组件有一个名为 spot 的输入变量。



所需的输出必须如下所示: / p>

 < table> 
< tbody>
< tr> ...< / tr>
< tr> ...< / tr>
< / tbody>
< table>

我尝试了以下方法:

 <表> 
< tbody>
< spot-row * ngFor =spot spot of spots[spot] =spot>< / spot-row>
< / tbody>
< table>

但是这产生了

 <表> 
< tbody>
< spot-row>
< tr> ...< / tr>
< tr> ...< / tr>
< / spot-row>
< / tbody>
< table>

然后我尝试将组件选择器切换为 [spot-row] 并使用 ng-container

 < table> ; 
< tbody>
< ng-container spot-row * ngFor =spot spot of spots[spot] =spot>< / ng-container>
< / tbody>
< table>

但是,这产生了一个错误


错误:./SpotRowComponent类中的错误SpotRowComponent - inline
模板:0:0原因:未能在'节点'上执行'appendChild':
此节点类型不支持此方法


然后我试着 template

 < table> 
< tbody>