Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 角度5-每次迭代的缩进_Javascript_Angular - Fatal编程技术网

Javascript 角度5-每次迭代的缩进

Javascript 角度5-每次迭代的缩进,javascript,angular,Javascript,Angular,我正在HTML表中显示值,例如 <tbody> <tr *ngFor="let employee of employeeList; let i = index"> <td> {{i}} {{ employee.name }}</td> <td>{{ employee.address }}</td> </tr> </tbody> 使用i=index,我可以得

我正在HTML表中显示值,例如

<tbody>
    <tr *ngFor="let employee of employeeList; let i = index">
      <td> {{i}} {{ employee.name }}</td>
      <td>{{ employee.address }}</td>
    </tr>
  </tbody>

使用i=index,我可以得到每一行的索引。然而,我无法理解如何将每个索引转换为一个空间

如何创建一个
空间
组件,显示您想要的空间数量并在循环中使用它:

空间组件:

<ng-container *ngFor="let i of numbers">
    &nbsp;
</ng-container>

用法:

<ng-container *ngFor="let name of ['A', 'B', 'C', 'D', 'E', 'F']; let i = index">
  <spaces [count]="i"></spaces> {{ name }}<br/>
<ng-container> 

{{name}}

您可以为不间断空格返回unicode文本:

spaces(num) {
 let spaces = '';
  for (let i = 0; i < num; i++) {
   spaces += '\u00A0';
 }
 return spaces;
}
空格(num){
让空格=“”;
for(设i=0;i
并在html中调用它,如:

<tbody>
  <tr *ngFor="let employee of employeeList; let i = index">
    <td>{{spaces(i)}}{{employee.name}}</td>
    <td>{{employee.address}}</td>
  </tr>
</tbody>

{{spaces(i)}{{employee.name}}
{{employee.address}
<tbody>
  <tr *ngFor="let employee of employeeList; let i = index">
    <td>{{spaces(i)}}{{employee.name}}</td>
    <td>{{employee.address}}</td>
  </tr>
</tbody>