Sunday, 3 November 2019

What is a component in Angular?

A component in Angular is a class with a template and a decorator. So, in simple   terms a component in Angular is composed of these 3 things

Template - Defines the user interface. Contains the HTML, directives and bindings.

Class - Contains the code required for template. Just like a class in any object-oriented programming language like C# or Java, a class in angular can contain methods and properties. Properties contain the data that we want to display in the view template and methods contain the logic for the view. We use Typescript to create the class.

Decorator - We use the Component decorator provided by Angular to add metadata to the class. A class becomes an Angular component, when it is decorated with the Component decorator.


No comments:

Post a Comment