简体   繁体   中英

How to programmatically clear angular QueryList

I have a writers component with following implementation

export class WritersComponent implements AfterContentInit {

   @ViewChildren('writer') 
   allWriters: QueryList<WriterComponent>       

   reset() {
      //want to empty querylist
      this.allWriters.reset([])
   }    

}

I want to reset the entire querylist. I tried passing empty array allWriters method but it is not working. FYI: I am calling the component reset method from other component using ViewChild reference to WritersComponent.

As mentioned in Angular official documentation querylist is An unmodifiable list of items that Angular keeps up to date when the state of the application changes.

SO you can't reset it. If you want to reset it then use something different.may an array you can use

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