How to declare a component in Angular 2 ?

Member

by ashtyn , in category: Technology , 3 years ago

How to declare a component in Angular 2 ?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by oda.tromp , 3 years ago

Components in Angular 2 are simply directives that are always associated with a direct template. Angular 2 components have an extremely well defined life-cycle. When working with angular components, we can make use of interfaces which allows us to implement functionality for different times in a components lifecycle. A component must belong to an NgModule in order for it to be usable by another component or application. Components can even control their runtime behaviour by implementing various Life-cycle hooks.


Declaration of component:

@component ({selector: 'great', template: 'hello {{name}}!'})

Class greet{

    Name: string = 'world';

}

Components always have a template and only one component can be instantiated per an element in a template. When a component is instantiated, angular creates a change detector, which is responsible for propagating the component’s building.