...
Consider this basic service
Notice the decorator, it marks this class as Injectable. Now we need inject it in a desired component, see the section below.
Info | ||
---|---|---|
| ||
You must make sure your class is registered as a provider of a service. This is done through the metadata in the @Injectable decorator declaration, the providedIn argument. When you provide the service at the root level, Angular creates a single, shared instance of |
Injecting a Service
Make the changes to your code and see what happens when you run it (remember in this example, the HEROES entity is a predefined array of Hero objects).