0

I have just started working on angular 2 and i need to know what are directives and what is the difference between and directives and components. Also i need a basic idea on dom elements in angular 2.

Shubashree Ravi
  • 261
  • 1
  • 16
  • checkout https://stackoverflow.com/questions/32680244/directive-v-s-component-in-angular – Dhyey Jul 05 '17 at 13:17
  • The article [Here is why you will not find components inside Angular](https://hackernoon.com/here-is-why-you-will-not-find-components-inside-angular-bdaf204d955c) explains the low level differences between the two – Max Koretskyi Jul 05 '17 at 13:28
  • Possible duplicate of [@Directive v/s @Component in Angular](https://stackoverflow.com/questions/32680244/directive-v-s-component-in-angular) – ventiseis Jul 05 '17 at 17:44

1 Answers1

0

A component is a directive-with-a-template and the @Component decorator is actually a @Directive decorator extended with template-oriented features.

Details : http://www.codeandyou.com/2016/01/difference-between-component-and-directive-in-Angular2.html

Directive vs Component

Components

To register a component we use @Component meta-data annotation. Component is a directive which uses shadow DOM to create encapsulated visual behavior called components. Components are typically used to create UI widgets. Component is used to break up the application into smaller components. Only one component can be present per DOM element. @View decorator or templateurl template are mandatory in the component.

Directive

To register directives we use @Directive meta-data annotation. Directive is used to add behavior to an existing DOM element. Directive is use to design re-usable components. Many directives can be used per DOM element. Directive doesn't use View.

Subtain Ishfaq
  • 793
  • 9
  • 16