0 votes
in Angular by

What are class decorators?

1 Answer

0 votes
by
Class Decorators are the highest-level decorators that determine the purpose of the classes. They indicate to Angular that a specific class is a component or module. And the decorator enables us to declare this effect without having to write any code within the class.

Example:

import { NgModule, Component } from '@angular/core';  
@Component({  
  selector: 'class-component',  
  template: '<div> This is a class component ! </div>',  
})  
export class ClassComponent {  
  constructor() {  
    console.log('This is a class component!');  
  }  
}  
@NgModule({  
  imports: [],  
  declarations: [],  
})  
export class ClassModule {  
  constructor() {  
    console.log('This is a class module!');  
  }  
}
It is a component or module in which no code in the class is required to tell Angular. We only need to design it, and Angular will take care of the rest.
...