Page Contents

Home > @loopback/context > Context > get

Context.get() method

Get the value bound to the given key, optionally return a (deep) property of the bound value.

Signature:

get<ValueType>(keyWithPath: BindingAddress<ValueType>, options: ResolutionOptions): Promise<ValueType | undefined>;

Parameters

Parameter Type Description
keyWithPath BindingAddress<ValueType> The binding key, optionally suffixed with a path to the (deeply) nested property to retrieve.
options ResolutionOptions Options for resolution.

Returns:

Promise<ValueType | undefined>

A promise of the bound value, or a promise of undefined when the optional binding is not found.

Example

// get "rest" property from the value bound to "config"
// use `undefined` when no config is provided
const config = await ctx.get<RestComponentConfig>('config#rest', {
  optional: true
});