0 votes
in Angular by
What is the Component Decorator in Angular?

1 Answer

0 votes
by

TypeScript classes are used to create components. This class genre is then decorated with the "@Component" decorator. The decorator's function is to take a metadata object holding component information and decorate it.

A Decorator is always preceded by @. The Decorator must come before the class definition. We can also make our own decorators.

Example: The example below shows us a Class decorated with the @Component decorator.

import {Component} from '@angular/core';

@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    title = 'Example component';
}

The metadata object received by the decorator has values such as templateUrl, selector, and others, with the templateUrL property pointing to an HTML file that defines what you see on the application.

...