Understanding Ionic 4/Angular : @Component decorator
Receive new Ionic 4 tutorials.
Thanks to ES6+ and TypeScript, Ionic/Angular v4 has access to object oriented and modern features such as classes and decorators.
Decorators are used to decorate classes.
Decorating a class specify its role and provides it with specific functionality.
@Component decorator exists in the
@angular/core package and used to make a class as a component.
A component is a software pattern adopted by many modern and popular frameworks like React and Angular. In these frameworks we build our app by composing components that use and communicate with each other.
Each component is self dependent and standalone.
This way of building apps has many advanatages and encourages separation of concerns and easy team collaboration.
In this tutorial, we are going to discuss the
@Component decorator and learn how to use it.
To use the
@component decorator we first need to import it using the simple and modern import system supported by ES6+ and TypeScript:
@Component Decorator Options
@Component decorator has many options that you can specify for you decorated class to use. The most used parameters are:
Which used to directly specify the html code that should be used as the template
Used to specify the relative path of the HTML file to use as a template by the component which should live in
As we have seen in this tutorial. The
@Component decorator is the most important decorator used by Ionic 4/Angular. This decorator is a part of Angular core and is used to create Angular components which are the basic buildings of any Angular application.
About the Author
Read our other tutorials
- Angular Tutorial
- Laravel 6 Tutorial
- React Tutorial
- React Hooks Tutorial
- React Native Tutorial
- Webpack Tutorial
- PHP Tutorial
- Django Tutorial
- Java Spring Tutorial
- Rails 6 Tutorial
- Ionic 4 Tutorial
- TypeScript Tutorial
- Bootstrap 4 Tutorial
- Electron Tutorial
- Cordova Tutorial
- HTML Tutorial
- GraphQL Tutorial
- CSS Grid Layout Tutorial
- PWA Tutorial