Patryk Brejdak
Patryk Brejdak

Reputation: 1601

Angular 2 Parent component calls multiple child components method

I'm building a separated boxes as angular 2 components which are uploading photos to server and then if receive success from server then there is sending a request to create an record in db. the structure is simple which is presented below. There can be n child's and when user clicks a button to upload all I need to call upload method in every child. Normally I would use service and subscribe method but I want to add queue to prevent overloading server. Is there any way to achieve it in this component logic?

<parent>
   <child>
   <child>
   ...
   <child>
</parent>

Upvotes: 0

Views: 940

Answers (1)

Fabien Greard
Fabien Greard

Reputation: 1894

You may think about output your data form each of your child into your parent component then you can send each data one by one if you want.

Ex :

<parent>
   <child (dataToSend)="handleDatatoPush($event)"></child>
   <child (dataToSend)="handleDatatoPush($event)"></child>
   ...
   <child (dataToSend)="handleDatatoPush($event)"></child>
</parent>

parent component:

handleDatatoPush(dataReceive: any){
//your logic even if i would do something like that
this.dataToSend.push(dataReceive);
}

Then you may send your data one by one in your sendAll function.

Upvotes: 1

Related Questions