In Angular v2, “everything is a component.” Components are the main way in which we build and specify elements and logic on the page, through both custom elements and attributes that add functionality to our existing components.
Angular applications are made up of components.
A component is the combination of an HTML template and a component class that controls a portion of the screen. Every component begins with an @Component decorator function that takes a metadata object. The metadata object describes how the HTML template and component class work together. Basically, a component is anything that is visible to the end user and which can be reused many times within an application.
A component is the combination of an HTML template and a component class that controls a portion of the screen. Every component begins with an @Component decorator function that takes a metadata object. The metadata object describes how the HTML template and component class work together. Basically, a component is anything that is visible to the end user and which can be reused many times within an application.
We attach @Component, a TypeScript decorator, which allows us to modify a class or function definition and add metadata to properties and function arguments.
- selector -is the element property that we use to tell Angular to create and insert an instance of this component.
- Template -is a form of HTML that tells Angular what needs to be to rendered in the DOM.
- MetaData-This is extra data defined for the Angular class.It's defined with a decorator
Now, let's open the app.components.ts page; This is an example of component
- import {
- Component
- } from '@angular/core';
- @Component({
- selector: 'my-app',
- template: `<h1>My first {{name}}</h1>`,
- })
- export class AppComponent {
- name = 'Angular2 Application';
- }
- export class AppComponent { name = 'Angular2 Application'; }
We are defining a class called AppComponent.


Join the conversation! Your thoughts help the community grow.