Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Injectables are a singleton only per IonicPage and not for the whole app

$
0
0

@mburger81 wrote:

We have a app which is using several IonicPage Components which would be lazy loaded.

In any of this IonicPage we have an html code like this

<ion-header>
    <custom-toolbar></custom-toolbar>
</ion-header>
<ion-content>
  .....
</ion-content>

So you can see, in the ion-header we have a CustomToolbarComponent which is a angular component loaed by an angular module. So until here anything is fine and it works great.

The CustomToolbar is injecting in his constructor a injectable global service.

@Component({
    selector: 'custom-toolbar',
    templateUrl: 'custom-toolbar.html'
})
export class CustomToolbarComponent {
    constructor(public myService: MyService) {

and this is our global service which should be injected only once per app.

@Injectable()
export class MyService {}

The problem is, we have N myService object injectes and app per N IonicPage, so this would not be a singleton per app but per page.

So the question is, should this not be a bug?? Or I'm missing something on singletons and angular?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



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