What is Decorators in Angular 5
- 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.
- Decorators are simply functions that return functions. These functions supply detadata to angular about a particular class, property, value or method.
- Decorators are invoked at run-time.
- Decorators allow you to execute functions. For example @Component executes the Component function imported from Angular 5.
Some Common Decorators
- @NgModule() to define modules
- @Compomnent() to define components
- @Injectable() to define services
- @Input() and @Output() to define properties that send and receive data from DOM
- There are many built-in decorators available in angular and many properties on each decorators
Types of Decorators
- Class Decorators – e.g. @Component and @NgModule
- Property Decorators for properties inside class- e.g. @Input and @Output
- Method Decorators for methods inside classes- e.g @HostListner
- Parameter Decorators for parameters inside class constructors – e.g. @Inject
- Each decorators has unique role.
I’m a full-stack developer. My hobby and profession to write blog and programming tips that helps to others. I am a great admirer of PHP, Laravel, Codeigniter, AngularJS, Vue.js, Javascript, JQuery, WordPress, Plugin Development, Theme Development and Bootstrap from the early stage.
Leave a Reply