Search code examples
angularionic3ionic2-select

Ionic2 + Application


I'm a bit confused about the application instantiation hierarchy, especially for providers. So basically you do the following in app.module.ts

import { myService} from '../providers/myService/myService';

and add it to the

@NgModule collection
    providers:[
        bla bla,
        myService
    ]

Now if I import and instantiate MyService in the app.components.ts does that make it a singleton for the whole app?

Every time I have wanted to use it on a page I have done the import and page constructor thing (e.g. myServ: myService)...but does that create a new instance or use the one created from app.components.ts.

I would love an explanation of the life-cycle of the components so the I know what I'm doing (well, as best as possible!!)


Solution

  • Injected Services in Ionic2+ are indeed Singletons and Ionic will instantiate and configure them during framework initialization.