Javascript 如何仅在一个div中运行函数2

Javascript 如何仅在一个div中运行函数2,javascript,jquery,angular,Javascript,Jquery,Angular,我有*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

我有*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>

{{group.name}
//在这里,我想调用函数,其中显示该组中的列表
//这是我写的,但不起作用


{{listGroup.name}



我假设您在
readListsGroup
中设置了属性
listsInGroup

它不起作用,因为您正在div for循环中调用
readListsGroup
。 这意味着
listsInGroup
具有第一组的值,紧接着它具有第二组的值,依此类推。循环的div结束后,
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函数
readListsGroup(group)
{
  const listsInGroup = findit();
  return listsInGroup;
}