Angular 2 Decorator


Angular 2 Decorator

Angular 2 Decorator are functions that are invoked with a prefixed @ symbol, and immediately followed by a class name or parameter or method or property.

Angular 2 Decorator used to supply information about the class, parameter or method.

Angular 2 Decorator is also known as Angular metadata.

You might have noticed in previous posts we have written Angular class with @Component, here @Component() is nothing but a decorator.

List of decorators in Angular

  1. @Component
  2. @NgModule
  3. @Input
  4. @Output
  5. @Injectable

@Component decorator

import { Component } from '@angular/core';
@Component({
 selector: 'hello-world',
 template: '<h1>Hello World</h1>',
 })
 export class HelloWorldComponent {
 constructor() {}
 }

@NgModule decorator

import { NgModule } from '@angular/core';
@NgModule({
 imports: [],
 declarations: [],
 })
 export class CommonModule {
 constructor() {}
 }

 






Full-stack web and mobile app development company Contact Us : Skype: indore.webcoder Email: info@w3sparks.com Sales: +91 8085506229