How to create a singleton service

Edit: This is no longer the correct solution in the latest versions of Ionic 2. See shaikhspear’s reply below.


Inject it into the @App itself:

@App({
  templateUrl: 'build/app.html',
  providers: [ConferenceData, UserData]
})

then import it in the @Page to use it. See the conference app:

https://github.com/driftyco/ionic-conference-app/blob/master/app/app.js#L10-L13

https://github.com/driftyco/ionic-conference-app/blob/master/app/pages/schedule/schedule.js#L12

3 Likes