Trails Packages
    Preparing search index...

    Interface ApplicationContext

    A service provided by the system, useful for accessing values that are global to the application.

    interface ApplicationContext {
        getApplicationContainer(): HTMLElement;
        getHostElement(): HTMLElement;
        getLocale(): string;
        getRoot(): Document | ShadowRoot;
        getShadowRoot(): ShadowRoot | undefined;
        getSupportedLocales(): readonly string[];
        setLocale(locale: string | undefined): void;
    }

    Hierarchy (View Summary)

    Index

    Methods

    • The HTML element containing the rest of the application inside the current web component.

      This element can be used as a root component to find other dom elements within the same application, for example:

      // Correct:
      const node = ctx.getApplicationContainer().querySelector('.my-element');

      // Incorrect because cannot search in shadow roots
      const node = document.querySelector('.my-element');

      Returns HTMLElement

    • The web component's host element. This dom node can be accessed by the host site.

      Returns HTMLElement

    • Returns the current locale of the application.

      E.g. "de-DE"

      Returns string

    • A root node that resolves to the the shadow root or the site's document.

      For example:

      const ctx: ApplicationContext = ...;
      const node = ctx.getRoot().getElementById("id"); // Correct with or without shadow root.

      Returns Document | ShadowRoot

    • The current web component's shadow root. This shadow root is located inside the host element.

      NOTE: This method returns undefined if the application does not use a shadow root.

      See also ApplicationConfig.disableShadowRoot and ().

      Returns ShadowRoot | undefined

    • Returns the locales supported by the application, i.e. the locales that have associated i18n messages.

      For example: ["de", "en"]

      Returns readonly string[]

    • Changes the application's locale. locale must be one of the supported locales, see () or undefined (for automatic locale). Note that locale does not need to be a precise match, e.g. "de-DE" is also valid if "de" is supported.

      NOTE: This method will currently trigger a full restart of the application. Altering the locale on the fly is possible in theory but has not been implemented yet.

      Parameters

      • locale: string | undefined

      Returns void