繁体   English   中英

Angular。 等待 viewchildren 更新

[英]Angular. Wait for viewchildren to be updated

我想通过ngFor更新组件模板使用的组件属性“rows”:

    ngFor="let row of rows"
... render child components 

子组件由

@ViewChildren(ChildComponent) children: QueryList<ChildComponent>;

我当前的伪代码(更新并应该等待children )看起来像这样:

fooMethod(): void {
  rows = ...increase rows count
  // wait here for children to be updated!
  for child of children {
      // process child 
   }
}

目前仅在执行fooMethod后更新子项

问题是我必须等待在更新rows属性以进一步处理项后填充子项: QueryList

我怎样才能做到这一点?

先感谢您!

您可以在 viewchildren 中执行代码,例如:-

@ViewChildren(ChildComponent) 
set children(components: QueryList<ChildComponent) {
  // your code here
}

暂无
暂无

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

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