繁体   English   中英

如何仅在一格Angular 2中运行功能

[英]How to run function only in one div Angular 2

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

我假设您在readListsGroup设置属性listsInGroup
它不起作用,因为要在div中调用readListsGroup进行循环。 这意味着listsInGroup具有第一组的值,紧随其后具有第二组的值,依此类推。 div for循环结束后, listsInGroup包含最后一个值(最后一个组的值),并且此值绑定到所有div。 我在写吗?

您可以在user184994写入时重写模板:

<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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM