In Angular 2, Components are the main way we build and specify elements and logic on the page. Questions should include code examples sufficient to reproduce the problem.
Declare reusable UI building blocks for an application.
Each Angular component requires a single @Component annotation. The @Component annotation specifies when a component is instantiated, and which properties and hostListeners it binds to.
When a component is instantiated, Angular
creates a shadow DOM for the component. loads the selected template into the shadow DOM. creates all the injectable objects configured with providers and viewProviders. All template expressions and statements are then evaluated against the component instance.
Hello world sample component
import { Component, Input } from '@angular/core';
@Component({
selector: 'hello-world',
template: `Hello {{name}}`
})
export class HelloWorldComponent{
@Input() name: string;
}
Use:
<hello-world [name]="'world'"></hello-world>