Interviews3 answers
How many types of Decorator are present in Angular?
3 Answers
Class decorators, e.g. @Component and @NgModule
Property decorators for properties inside classes, e.g. @Input and @Output
Method decorators for methods inside classes, e.g. @HostListener
Parameter decorators for parameters inside class constructors, e.g. @Inject
Prashanth KumarPosted Mar 29, 2018, 1:12 AM EDT
Decorators are functions, and there are four things (class, parameter, method and property) that can be decorated; consequently there are four different function signatures for decorators:
class: declare type ClassDecorator = (target: TFunction) => TFunction | void;
property: declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
method: declare type MethodDecorator = (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void;
parameter: declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
Srinivas PabballaPosted Mar 16, 2018, 5:51 AM EDT
1. Class Decorator e.g. @Component and @NgModule.
2. Property Decorator e.g. @Input and @Output.
3. Method Decorator e.g. @HostListner
4. Parameter Decorator e.g. @Inject.
Mahesh VermaPosted Mar 12, 2018, 8:29 PM EDT



