The first thing to remember is that the syntax in this thread is five years old. Specifically, the
@Page decorator no longer exists - it used to be an Ionic-specific thing that has been subsumed under current recommendations to just use Angular’s
The second thing I want to emphasize is that naked scalar singletons in services are a bad idea unless you are 150% sure that never ever ever is it even remotely possible that you’ll ever want to change them while the app is running. If there’s even a chance that they’ll become mutable, expose them as
Observables out of the service and
subscribe to them in the places that reference them (either for reading or for writing).
So, to summarize so far, you probably don’t want to be doing exactly what OP was in the first place, and you definitely don’t want to be trying to use any of the old syntax from this thread verbatim.
Now, to address your direct question.
Refer back to the first post in this thread that contains code. It has this decorator:
providers: [User, DB]
The point under discussion here initially was that the two pages decorated here weren’t seeing the same
User, and that’s because they were declared in
providers on each page. The way to get them both seeing the same
User is to only declare it in
providers of the
AppModule. You’re absolutely right that everybody needing access needs to inject it, but not everybody needs to declare it as a provider, and in fact doing so breaks the main point of shared services.