1.

What is the difference between component and directive in Angular 6?

Answer»
ComponentDIRECTIVE
A component is a directive used to SHADOW DOM to create and encapsulate visual behavior called components. They are typically used to create UI widgets.A Directive is usually used while adding behavior to an existing DOM element.
For registering a component, we use @Component metadata annotation attributes.For registering directives, we use the @Directive meta-data annotation attribute.
It is also used to break up the APPLICATION into smaller components.It is mainly used to DESIGN re-usable components.
Only one component is allowed to be present per DOM element.Multiple directives can be used in a per DOM element.
@View decorator or TEMPLATE URL template is mandatory in a component.A Directive does not have View
A component is used to define pipes.You can’t define Pipes in a directive.


Discussion

No Comment Found