2

I'm using ionic framework and I've noticed that on a lot of my pages i'm using the same modules.

import { Http } from '@angular/http';
import { Storage } from '@ionic/storage';

Then I have to set them in my constructor on each page.

constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http, private storage: Storage)

Is there a better way to auto include these on all my pages? Or is what I'm doing the best solution?

sebaferreras
  • 44,206
  • 11
  • 116
  • 134
user2570937
  • 802
  • 3
  • 17
  • 34

1 Answers1

1

Is there a better way to auto include these on all my pages?

I'm afraid there is not. You could create a BasePage component where you can add all the imports and then in the rest of the pages you would need to import that BasePage to inherit the properties, but I guess it would be pretty much the same (this solution would make sense if you have a lot of imports in all the pages, or some repeated code/methods used by all the pages; in that scenario you could place that code in the BasePage and use it in every other page).

Just in case if you want to take a look at how that could be done, please take a look at this SO answer

So, if you are only including a few imports and properties in the constructor, what you're doing is the best solution.

sebaferreras
  • 44,206
  • 11
  • 116
  • 134