Angular Directives Vs. Components

Using Angular Component and Angular Directive both are equally important and are used while building Angular Application. One of the major differences between Angular Component and Angular Directive is that every Angular Component must and must have a view/template associated with it, without a view,  Angular Component cannot be created whereas Directive does not have to particularly have view associated with it.


Directives




Components

Whenever we want to register the Angular component we need to use meta-data annotation @Component. Angular Components are a subset of Angular Directive and they are always associated with a template/View. Unlike other directives, only one component can be instantiated for a given element in a template. Every Component in Angular belongs to a NgModule so that it can be available for being used by another component in your Angular Application.

To make the newly created Angular Component a member of NgModule, we should be adding this component name in the declarations field of the NgModule metadata. Components are typically used to create UI widgets and small components which are used across the application. Angular Component can also be used to define pipes. The component is used to break up the application into smaller components and make core readability better. @View decorator OR templateUrl template is mandatory when creating Angular Component.





Comparison Between Directives vs. Components






Post a Comment

0 Comments