Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

348
Views
Iterar a través de múltiples instancias de @ViewChild del mismo componente angular2

Tengo una aplicación Ionic 2 con un ParentComponent que llama al método ChildComponent @ViewChild para activar varios ChildComponents. Uno de los ChildComponents se instancia dos veces en la vista con diferentes parámetros como este:

 <ChildComponent [startFrom]="0" [limitTo]="1"></ChildComponent> <ChildComponent [startFrom]="1" [limitTo]="1"></ChildComponent>

Después de un cambio de estado del dispositivo fuera de línea/en línea, llamo al método de ChildComponent para actualizar una lista de elementos que devuelve.

 @ViewChild(ChildComponent) childComponent: ChildComponent; ngOnInit(): void { this.networkService.connectSubscription(() => { this.childComponent.getItems(); }); }

El problema aquí es this.childComponent solo obtiene la primera instancia de ChildComponent de los dos.

¿Hay alguna forma de iterar a través de varias instancias del mismo componente @ViewChild para poder hacer algo como this.childComponent1.getItems() y this.childComponent2.getItems() ?

Gracias por tu ayuda.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

@ViewChildren(ChildComponent) childComponents: QueryList<ChildComponent>;
 ngAfterViewInit(): void { this.networkService.connectSubscription(() => { this.childComponents.toArray(); }); }
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!