How to declare a component in Angular 2 ?

devquora
devquora

Posted On: Feb 22, 2018

 

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.

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    Angular 2 Interview Questions

    What is Angular 2 ?

    Angular 2 is a completely revived component-based framework in which an application is a tree of loosely coupled compon..

    Angular 2 Interview Questions

    List some advantages of Angular 2 over Angular1.

    Angular 2 is a re-written version of Angular1 and not an update. The best way to compare Angular 2 and Angular 1 is by f..

    Angular 2 Interview Questions

    What are the new features of Angular 2?

    Angular 2 is a platform that encompasses a wide range of capabilities. Some new features were added in Angular 2 which i..