How do I Access the Global Injector from a Page Class?

Every page in my app needs access to the i18n services that has been set up as a provider in my App like this:

  providers: [I18nService]

I’ve created a base page class that all my Page classes extend:

export class BasePage {
    constructor(i18nService:I18nService) {
        this.locale = null;
        this.i18n = i18nService;
        this.i18n.getLocale().then((locale) => {
            this.locale = locale;

This works fine, but the annoying thing with this approach is that I have to do all of the DI in the child class and pass the service up to the parent with a super call:

export class MyChildPage extends BasePage {
  constructor( i18nService:I18nService) {

Is there a way I can get reference to the I18nService in the base class without relying on the child class to pass it in the constructor? For example, in Java, I could do something like: applicationContext.getBean(“i18n”) in order to fetch the instance straight out of the context. Is there something similar in Ionic 2?

1 Like