简体   繁体   中英

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="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:

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

The problem is I have to wait for children to be populated after rows property is updated to work further with children: QueryList .

How can I do this?

Thank you in advance!

You can do your code inside viewchildren like:-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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