Wednesday, November 14, 2018

How to Share a Service



For services you need to add the function forRoot() to the shared Module. You are going to end up with something like this:
By convention, the forRoot static method both provides and configures services at the same time. In the case of this kind of shared Modules (that’s expose services), you need to add them and call the forRoot in your root module (AppModule usually) to be certain of having a global instance of the exposed services.
You can also pass a params to the forRoot method to configure the service initialization. If you need params your code is going to end up something like:
In your service you receive this values on the constructor:


No comments:

Followers

Link