The @Value Decorator
Main
The @Value decorator allows you to access properties from your properties.json in a programatic way, this means, by using the @Value decorator, you can interact with your configuration in your components or native classes.
Usage
Syntax:
@Value(propertyKey: string)propertyKey
Key reference of your property. If nested, please separate by using dots (.)
Example:
// ./src/main/resources/properties.json
{
"mandarine": {
"hello-message": "Bonjour!"
},
"customKey": "Here goes my custom value"
}import { Value } from "https://deno.land/x/mandarinets/mod.ts";
export class ValueDecoratorTest {
@Value('customKey')
public static customKey: string;
@Value('mandarine.hello-message')
public bonjour: string;
}
console.log(ValueDecoratorTest.customKey); // Here goes my custom value
console.log(new ValueDecoratorTest().bonjour); // Bonjour!In the example above we can see how we are using @Value on top of two different class fields: one that is static, and one that is not. Although, it works for both.
In the example above, we can also see how we are using nested properties with the @Value decorator.
Last updated
Was this helpful?