Allows looking up contextual data set on a <sci-router-outlet> at any parent level.

The platform allows associating contextual data with an outlet, which then is available in embedded content using ContextService. Contextual data must be serializable with the structured clone algorithm.

Each outlet spans a new context. A context is similar to a Map, but is linked to its parent outlet context, if any, thus forming a hierarchical tree structure. When looking up a value and if the value is not found in the outlet context, the lookup is retried on the parent context, repeating until either a value is found or the root of the context tree has been reached.

The platform sets the following context values by default:

Key Value type Description
ɵOUTLET OutletContext Information about the outlet which embeds the microfrontend.
ɵACTIVATION_CONTEXT ActivationContext Information about the activation context if loaded by an activator. See ActivatorCapability for more information about activators.

Hierarchy

  • ContextService

Implements

  • PreDestroy

Constructors

Methods

  • Checks if a context value is associated with the given name at any level in the context tree.

    Parameters

    • name: string

      The name of the context value to check if present.

    Returns Promise<boolean>

    A Promise that resolves to true if a context value is associated with the given name, or that resolves to false otherwise.

  • Looks up the context value associated with the given name.

    The Promise resolves to the most specific value, i.e., the value of the closest context that has a value associated with that name. To collect all values in the context hierarchy associated with that name, set ContextLookupOptions#collect to true.

    If not finding a value associated with the given name in the current context, the lookup is retried on the parent context, repeating until either a value is found or the root of the context tree has been reached. If not finding a value in any context, the returned Promise resolves to null.

    Type Parameters

    • T

    Parameters

    • name: string

      The name of the context value to look up.

    • Optional options: ContextLookupOptions & {
          collect: false;
      }

      Instructs how to look up the context value.

    Returns Promise<null | T>

    A Promise that resolves to the value associated with the given name, or null if not finding a value.

  • Looks up context values associated with the given name.

    The Promise resolves to all associated values in the context tree as array in context-descending order, i.e., more specific context values precede others, in other words, values of child contexts precede values of parent contexts. If not finding a value in any context, the Promise resolves to an empty array.

    To only obtain the most specific value, i.e., the value of the closest context that has a value associated with that name, set ContextLookupOptions#collect to false.

    Type Parameters

    • T

    Parameters

    • name: string

      The name of the context values to look up.

    • options: ContextLookupOptions & {
          collect: true;
      }

      Instructs how to look up context values.

    Returns Promise<T[]>

    A Promise that resolves to the values associated with the given name, or an empty array if not finding a value. Collected values are sorted in context-descending order, i.e., more specific context values precede others, in other words, values of child contexts precede values of parent contexts.

  • Type Parameters

    • T

    Parameters

    Returns Promise<null | T | T[]>

  • Observes the names of context values registered at any level in the context tree.

    Returns Observable<Set<string>>

    An Observable that emits the names of context values registered at any level in the context tree. Upon subscription, it emits the names of context values currently registered, and then it emits whenever some value is registered or unregistered from a context. The Observable never completes.

  • Observes the context value associated with the given name.

    The Observable emits the most specific value, i.e., the value of the closest context that has a value associated with that name. To collect all values in the context hierarchy associated with that name, set ContextLookupOptions#collect to true.

    If not finding a value associated with the given name in the current context, the lookup is retried on the parent context, repeating until either a value is found or the root of the context tree has been reached. If not finding a value in any context, the Observable emits null.

    Type Parameters

    • T

    Parameters

    • name: string

      The name of the context value to observe.

    • Optional options: ContextLookupOptions & {
          collect: false;
      }

      Instructs how to look up the context value.

    Returns Observable<null | T>

    An Observable that emits the value associated with the given name, or null if not finding a value. Upon subscription, the Observable emits the currently associated value, and then continuously when it changes, at any level in the context tree. It never completes.

  • Observes the context values associated with the given name.

    The Observable emits all associated values in the context tree as array in context-descending order, i.e., more specific context values precede others, in other words, values of child contexts precede values of parent contexts. If not finding a value in any context, the Observable emits an empty array.

    To only obtain the most specific value, i.e., the value of the closest context that has a value associated with that name, set ContextLookupOptions#collect to false.

    Type Parameters

    • T

    Parameters

    • name: string

      The name of the context values to observe.

    • options: ContextLookupOptions & {
          collect: true;
      }

      Instructs how to look up context values.

    Returns Observable<T[]>

    An Observable that emits the values associated with the given name, or an empty array if not finding a value. Upon subscription, the Observable emits currently associated values, and then continuously when they change. It never completes. Collected values are emitted as array in context-descending order, i.e., more specific context values precede others, in other words, values of child contexts precede values of parent contexts.

  • Type Parameters

    • T

    Parameters

    Returns Observable<null | T | T[]>

Generated using TypeDoc