Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
Angular 如何判断哪一个孩子是最后一个_Angular_Ngfor - Fatal编程技术网

Angular 如何判断哪一个孩子是最后一个

Angular 如何判断哪一个孩子是最后一个,angular,ngfor,Angular,Ngfor,我有两个组件列表(父项)和项目(子项) 我想为最后一个子组件设置不同的样式。 我们如何才能做到这一点?在父组件中,我迭代子组件。我试图获取*ngFor索引(根据angular文档),并将类设置为: <ul class="list-group"> <app-item *ngFor="let traceGroup of tracesGroup; index as i" [traceGroup]="traceGroup"; [cla

我有两个组件列表(父项)和项目(子项)
我想为最后一个子组件设置不同的样式。
我们如何才能做到这一点?在父组件中,我迭代子组件。我试图获取*ngFor索引(根据angular文档),并将类设置为:

<ul class="list-group">
  <app-item *ngFor="let traceGroup of tracesGroup; index as i"
            [traceGroup]="traceGroup";
            [class.isLast]="i + 1 === tracesGroup.length"></app-item>
</ul>
但我犯了个错误

错误DOMEException:未能对“元素”:“;”执行“setAttribute”不是有效的属性名称

我还尝试通过这种方式获取索引
;设i=索引
但是,即使删除分号,仍然会出现错误。
代码有什么问题?从父组件到子组件以某种方式“标记”以便知道哪个子组件是最后一个组件的最佳做法是什么?
谢谢你的打字错误:

[traceGroup]="traceGroup";
                        ^^^
                      remove this

哦,对不起。我没注意到。感谢您的帮助您可以使用*ngFor=“…;let last=last”,请参阅