My goal is to create a shared service for my app.
import { Injectable } from '@angular/core';
@Injectable()
export class SharedService {
testService() {
console.log('share!');
}
}
However, when I attempt to inject this shared service in my app.component's providers and call it in the constructor of a child component like so:
constructor(public sharedService: SharedService) {}
, I encounter an error stating:
Can't resolve all parameters for MyComponent
. This error persists even if I try to inject the service in my app.module providers. What steps should I take to resolve this issue? Can someone provide an example of how to correctly inject a shared service for the entire app (which consists of multiple modules)?
In addition, with a routing system in place, I aim to have a shared service that allows me to modify its data from the component representing the current module.