UNPKG

@loopback/docs

Version:

Documentation files rendered at [https://loopback.io](https://loopback.io)

83 lines (43 loc) 1.68 kB
--- lang: en title: 'API docs: context.context.getbinding_1' keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI sidebar: lb4_sidebar editurl: https://github.com/loopbackio/loopback-next/tree/master/packages/context permalink: /doc/en/lb4/apidocs.context.context.getbinding_1.html --- <!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@loopback/context](./context.md) &gt; [Context](./context.context.md) &gt; [getBinding](./context.context.getbinding_1.md) ## 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:** ```typescript getBinding<ValueType>(key: BindingAddress<ValueType>, options?: { optional?: boolean; }): Binding<ValueType> | undefined; ``` ## Parameters <table><thead><tr><th> Parameter </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td markdown="1"> key </td><td markdown="1"> [BindingAddress](./context.bindingaddress.md)<!-- -->&lt;ValueType&gt; </td><td markdown="1"> Binding key </td></tr> <tr><td markdown="1"> options </td><td markdown="1"> { optional?: boolean; } </td><td markdown="1"> _(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. </td></tr> </tbody></table> **Returns:** [Binding](./context.binding.md)<!-- -->&lt;ValueType&gt; \| undefined