In TypeScript, the class serves as a reference that can be imported for use.
It is essential to have a class or member to decorate when using a decorator.
Once compiled, the annotation used to decorate the class will be retained. These annotations are utilized by Angular to configure the injector, determining which class should be created when a component needs to inject a specific member type.
You can add functionality to the constructor, such as performing actions when the module (and associated components/providers) are ready to be injected. This is one potential application for this feature.
[edit] Personally, I have utilized it to register a locale upon app startup.
export class AppModule {
constructor() {
registerLocaleData(localeDeCH);
}
}
This concept was inspired by this discussion, where the timing of calling registerLocaleData
was not specified.