I was looking into "how to use Constants on Angular2" and found this post with this answer where one have to create a class with an OpaqueToken
, import it on app.module
and use it as a provider in the @NgModule
. In the Page Class or service import it and inject it with @Injectable()
.
Then I searched on how to create a "factory like in AngularJS" and find out this post about sharing data between components in Ionic2, in it you create a simple class without an OpaqueToken
and import it in app.components
, register it as provider
on @Component
and in the App constructor. Finally import it on the page class and inject it (no need to use @Inject()
)
Is there a difference between this two? at first glance seams like those both do the exact same thing and I find the second way easier.
Edit
User estus pointed out in a comment, the first one with the OpaqueToken
will inject a class and the second example inject a class instance. Does this means that with the first example every page will have their own instance of that class ? so 10 pages = 10 instances ? is it not counterproductive (or inefficient) for share static data/constants between them?