Page Contents
Home > @loopback/context > Context > getBinding
Context.getBinding() method
Look up a binding by key in the context and its ancestors. If no matching binding is found and options.optional is not set to true, an error will be thrown.
Signature:
getBinding<ValueType>(key: BindingAddress<ValueType>, options?: {
optional?: boolean;
}): Binding<ValueType> | undefined;
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | [BindingAddress](/doc/en/lb4/apidocs.context.bindingaddress.html)<ValueType> | Binding key |
| options | { optional?: boolean; } | _(Optional)_ Options to control if the binding is optional. If `options.optional` is set to true, the method will return `undefined` instead of throwing an error if the binding key is not found. |
Returns:
Binding<ValueType> | undefined