问题描述
我正在尝试在模板内使用*ngFor
迭代数组,并使用* ngIf搜索基于键的元素.现在,当条件与键匹配时,我想破坏*ngFor
.我想知道angular2中是否有任何选项可以根据条件中断ngFor
循环.
I am trying to iterate array using *ngFor
inside the template and searching for an element based on the key, using *ngIf. Now when the condition is matched with the key I want to break the *ngFor
. I wondered if there any option in angular2 to break the ngFor
loop based on condition.
推荐答案
没有任何选择可以破坏ngFor
.您可以使用自定义管道,该管道在满足条件的元素之后不返回值.
There is no option to break ngFor
. You can use a custom pipe that doesn't return values after the element where the condition is met.
有关更具体的方法,请提供有关您实际要完成的工作的更具体的信息.
For more concrete approaches please provide more concrete information about what you actually try to accomplish.
这篇关于在Angular 2中打破NgFor循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!