Gets the value of an `MetadataKey` for the field.
(key: MetadataKey<T, unknown, unknown>)
| 52 | |
| 53 | /** Gets the value of an `MetadataKey` for the field. */ |
| 54 | get<T>(key: MetadataKey<T, unknown, unknown>): T | undefined { |
| 55 | // We create non-managed metadata lazily, the first time they are accessed. |
| 56 | if (this.has(key)) { |
| 57 | if (!this.metadata.has(key)) { |
| 58 | if (key.create) { |
| 59 | throw new RuntimeError( |
| 60 | RuntimeErrorCode.MANAGED_METADATA_LAZY_CREATION, |
| 61 | ngDevMode && 'Managed metadata cannot be created lazily', |
| 62 | ); |
| 63 | } |
| 64 | const logic = this.node.logicNode.logic.getMetadata(key); |
| 65 | this.metadata.set( |
| 66 | key, |
| 67 | computed(() => logic.compute(this.node.context)), |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | return this.metadata.get(key) as T | undefined; |
| 72 | } |
| 73 | |
| 74 | /** Checks whether the current metadata state has the given metadata key. */ |
| 75 | has(key: MetadataKey<any, any, any>): boolean { |