Angular Component Decorator in Detail
In this article, I am going to discuss the Angular Component Decorator in Detail. Please read our previous article where we discussed the basics of Angular Components with some examples. At the end of this article, you will understand the Component Decorator and the different properties of component decorator in detail.
What is the Component Decorator in Angular?
Whenever you want to make a class as a component, then you need to decorate that class with @Component decorator.
The @Component decorator in angular provides metadata to a component that determines how to process, instantiate and use the component at runtime. If you are a dot net developer then you can compare this with the attribute in C# and if you are a java developer then you can compare this with annotations in Java.
The Component Decorator in Angular accepts one object and using that object you can configure the required metadata information to create and display the component in real-time.
Metadata Properties of Component Decorator:
In order to understand what metadata properties are provided by the component decorator, please have a look at the following image.
Let us understand each of the above metadata.
- changeDetection – change the detection strategy used by this component.
- templateUrl – URL in an external file that contains a template for the view.
- template – template defined inline template for the view.
- viewProviders – list of providers available for this component and the view of their children.
- animations – animation’s list of this component.
- moduleId – Module ID ES / CommonJS of the file in which this component is defined.
- encapsulation – strategy of style encapsulation used by this component.
- styleUrls – URL list for style sheets that will be applied to the view of this component.
- interpolation – custom interpolation markers used in the template of this component.
- styles – styles defined online that will be applied to the view of this component.
- preserveWhitespaces – Using this property, we can remove all whitespaces from the template.
- entryComponents – entryComponents is the list of components that are dynamically inserted into the view of this component.
We will discuss each of these metadata properties in detail, as we progress through this course. In the next article, I am going to discuss two important properties i.e. template and templateUrl in detail as well as explore the difference between them.
About the Author: Pranaya Rout
Pranaya Rout has published more than 3,000 articles in his 11-year career. Pranaya Rout has very good experience with Microsoft Technologies, Including C#, VB, ASP.NET MVC, ASP.NET Web API, EF, EF Core, ADO.NET, LINQ, SQL Server, MYSQL, Oracle, ASP.NET Core, Cloud Computing, Microservices, Design Patterns and still learning new technologies.