What is the difference between component and directive in Angular 6?
Component | Directive |
---|---|
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. |
BY Best Interview Question ON 16 Feb 2020