Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

How to create a singleton service

$
0
0

I am trying to create a singleton service at the app level to be used by various component pages. In angular 2, I would do this from the bootstrap method in the boot file:

bootstrap(MyApp, [MySingletonService]);

Then the service could be injected in the constructors of the various components as a singleton, that is giving each component the same instance.

But there is no boot file in Ionic 2, there is an @App component. And it looks to me that framework calls bootstrap on its own.

If I inject my service into a component page in Ionic 2 with

@Page({
templateUrl: 'app/myPage/myPage.html',
providers: [ MyService]

})

I get a new instance of my service, rather than a singleton. So in Ionic 2 how do you get a singleton service?


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>