How to create a singleton service

  1. in your app.ts :

ionicBootstrap(MyApp, [MyDataService]);

  1. in your component(s).ts :
@Component({
	templateUrl: 'html.html.html',
        /* do not add the declaration : [MyDataService] */
})
export class MyPage{
	constructor(myDataService: MyDataService) {
		// myDataService : singleton instance
	}
1 Like