Fahad Alanazi
Fahad Alanazi

Reputation: 1

how to use child components http response in parent component? Angular

I am new to Angular, and I am really confused with http requests,

what I need is, I have component A that will get list of IDs and it is common for several other components,

so in component B, I need to use the list of IDs from component A to get initial value ( first ID )

I tried to add @ChildView to B component but it is not working ( I think Angular is sending the HTTP request and do not wait for the response )

what I am doing is now is, I am sending the request from both component, and I really feel bad =)

Upvotes: 0

Views: 679

Answers (1)

ForestG
ForestG

Reputation: 18113

If the relation between componentA and componentB is :

  • ComponentA contains componentB: then passing data is usually achived by @Input() properties.
  • If it is the other way around, I suggest using an EventEmitter, or rather, a shared service, which can store your data.

To learn how to implement it and for examples of usage, I suggest reading the official guide about component interaction.

Upvotes: 1

Related Questions