Web Prepration

Web Concept Tutorials


What is Decorators in Angular 5

  1. Decorators are a features of type Script and are implemented as functions. The name of the decorators starts with @ symbols following by brackets and arguments, Since decorators are just function in type Script.
  2. Decorators are simply functions that return functions. These functions supply detadata to angular about a particular class, property, value or method.
  3. Decorators are invoked at run-time.
  4. Decorators allow you to execute functions. For example @Component executes the Component function imported from Angular 5.

Some Common Decorators

  1. @NgModule() to define modules
  2. @Compomnent() to define components
  3. @Injectable() to define services
  4. @Input() and @Output() to define properties that send and receive data from DOM
  5. There are many built-in decorators available in angular and many properties on each decorators

Types of Decorators

  1. Class Decorators – e.g. @Component and @NgModule
  2. Property Decorators for properties inside class- e.g. @Input and @Output
  3. Method Decorators for methods inside classes- e.g @HostListner
  4. Parameter Decorators for parameters inside class constructors – e.g. @Inject
  5. Each decorators has unique role.

0 comment on What is Decorators in Angular5

Write a comment

Your email address will not be published. Required fields are marked *