# Decorator Value
DecoratorModule | import { Value } from "@tsed/di" |
---|---|
Source | /packages/di/src/types/common/decorators/value.ts |
# Overview
function Value(expression: any, defaultValue?: any): (target: any, propertyKey: string) => void;
# Description
Return value from Configuration.
# Example
import {Env} from "@tsed/core";
import {Constant, Value} from "@tsed/di";
export class MyClass {
@Constant("env")
env: Env;
@Value("swagger.path")
swaggerPath: string;
@Value("swagger.path", "defaultValue")
swaggerPath: string;
constructor() {
console.log(this.swaggerPath) // undefined. Not available on constructor
}
$onInit() {
console.log(this.swaggerPath) // something
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22