What is the difference between Components and Directives?

 
Demo URL



@Components

@Directives

For register component we use @Component

meta-data annotation.


For register directives we use @Directive meta-data annotation.


Component is a directive which use shadow

DOM to create encapsulate visual behavior

called components. Components are typically

used to create Ul widgets.


Directives are used to add behavior to an existing DOM element.

Component is used to break up the application into smaller components.


Directive is used to design reusable components.



Only one component can be present per DOM element.


Many directive can be used in a per DOM element



Component is used to define pipes

You can't define Pipes in a directive.



@View decorator or templateurl template are

mandatory in the component.


Directives don't have a View.


No comments:

Post a Comment

Angular's new httpResource and a bonus hidden feature

  The first   release candidate   for   Angular 19.2   is out, and it includes the new experimental   httpResource . This is essentially a s...

Best for you