我有* ngFor与群组(其工作),我需要显示“listofGroup”(在控制台工作但在视图中没有),在这个特定的组中,我的问题是:如何在Angular2中的特定div中运行函数
我的HTML群组
<div *ngFor="group in groups">
<h4>{{group.name}}</h4>
//here I want to call function where shows list in this group
//I wrote this but not working
<ul (load)="readListsGroup(group._id)">
<li *ngFor="let listGroup of listsInGroup">
<span>{{listGroup.name}}</span>
</li>
</ul>
</div>
答案 0 :(得分:0)
我假设您在listsInGroup
中设置了属性readListsGroup
它不起作用,因为你在div中调用readListsGroup
循环。
这意味着listsInGroup
具有第一组的值,并且在此之后立即具有第二组的值,依此类推。在div for循环结束后,listsInGroup
包含最后一个值(最后一个组的值),并且该值绑定到所有div。我写的?
您可以将模板重写为user184994 write:
<div *ngFor="group in groups">
<h4>{{group.name}}</h4>
//here I want to call function where shows list in this group
//I wrote this but not working
<ul>
<li *ngFor="let listGroup of readListsGroup(group)">
<span>{{listGroup.name}}</span>
</li>
</ul>
</div>
代码:
readListsGroup(group)
{
const listsInGroup = findit();
return listsInGroup;
}