简体   繁体   中英

Pass api response from one component to another component in Angular

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.

ps the API response is n array of strings.

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

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