In my current project, I am working on developing a service that can parse data to different components based on various routes.
When I call this service within the same component, everything works as expected and I get the desired results. However, when I attempt to retrieve the set results from another component, the service returns undefined.
Below is the code snippet for my service:
import {Injectable} from '@angular/core';
@Injectable()
export class TestService {
public _test:any;
set test(value:any) {
this._test = value
}
get test():any {
return this._test;
}
}
I assign a value to the service like so:
this.testService.test = 3;
To access the data stored in the service within my component, I use the following code:
console.log(this.testService.test)
While this setup functions correctly when used within the same component with matching imports, providers, and constructor, it does not work across sibling components.
If anyone has any suggestions or solutions to this issue, your help would be greatly appreciated.
If you need any additional code snippets or information, please feel free to let me know.