【发布时间】:2017-06-20 09:52:42
【问题描述】:
有人可以告诉我如何在执行 ngFor 时切换图标吗?
问题陈述: 我正在使用 *ngFor 循环遍历数组并显示类别名称。在点击当天,我需要打开一个手风琴并显示类别详细信息(我可以这样做)。 一旦手风琴打开,我需要用 fa-minus 替换 fa-plus 图标,反之亦然,我只需要在点击的日子这样做。
我怎样才能有效地做到这一点?
this.categoryList = [
{type: 'space', name: 'Space'},
{type: 'energy', name: 'Energy'},
{type: 'comfort', name: 'Comfort'},
{type: 'maintenance', name: 'Maintenance'},
{type: 'reporting', name: 'Reporting'}
];
HTML
<div class="{{category.type}}" *ngFor="let category of categoryList">
<div data-toggle="collapse" [attr.href]="'#'+'category-'+category.type">
<div class="title {{category.name}}">{{category.name}}</div>
<div>
<i class="fa fa-plus"></i> //needs to toggle between plus and minus
<i class="fa fa-minus"></i> //needs to toggle between plus and minus
</div>
</div>
<div class="collapse" id="category-{{category.type}}">
//details
</div>
</div>
【问题讨论】:
-
你在为手风琴使用 jQuery 吗?
-
@RehbanKhatri 引导!!手风琴很好,它的工作!只有我需要知道如何切换 fa-plus 和 fa-minus。
-
请出示您的手风琴代码,也许有一个可以使用的状态变量! :)
-
应该可以“开”多天吗?
-
我认为这是对您的特定问题的更好答案,摘要和详细信息元素是为此目的而构建的,而不是索引 - stackoverflow.com/a/42027647/7511922
标签: loops angular typescript ngfor angular-ng-if