Pass data between independent components in Angular 2 -


i'm beginner in angular 2 , developing small spa. in component login receive data via http service, set data class user , need data available in other components. problem components independent (don't have parent-child relation). there mechanisms in angular 2 pass data in way?

first of recommends use service pass data between components.

here example how components can communicate using 3 diff. ways,

angular2-playground demo code available on github

suppose if creating service s1 , providing service in app.module.ts file create singleton instance of service, if make changes in service component 1, can modified data in component 2.

or can add service in separate module separate functionality, service can accessible in module only.

summary: can use services passing data between components, helpful.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -