Home > Back-end >  Pass api response from one component to another component in Angular
Pass api response from one component to another component in Angular

Time:07-08

I have a component named server and another component named process. I am taking response from server.service.ts to server.component.ts and I want that response in process.component.ts. Any ideas on how this can be achieved.

p.s. the API response is n array of strings.

CodePudding user response:

There are many way to pass informations from one component to another component:

  • If they are parent child you can pass it using @Input and @Output (it depends on the direction you need to use)
  • If they are in different pages you can pass it in various ways using the routing (route parameter, query string, url fragment, state object)
  • You can save the information in a service
  • You can use a Subject to which the first component will next the object and the second component is subscribed to get the updates
  • Related