简体   繁体   English

Angular。 等待 viewchildren 更新

[英]Angular. Wait for viewchildren to be updated

I would like to update component's property "rows" that is used by component's template via ngFor :我想通过ngFor更新组件模板使用的组件属性“rows”:

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

Child components are collected by子组件由

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

My current pseudo code (that updates rows and should wait for children ) looks like that:我当前的伪代码(更新并应该等待children )看起来像这样:

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

Children are updated only after fooMethod is executed at present目前仅在执行fooMethod后更新子项

The problem is I have to wait for children to be populated after rows property is updated to work further with children: QueryList .问题是我必须等待在更新rows属性以进一步处理项后填充子项: QueryList

How can I do this?我怎样才能做到这一点?

Thank you in advance!先感谢您!

You can do your code inside viewchildren like:-您可以在 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