Angular 2 Interview question and answer 

What is the difference between @Component and @Directive in Angular?

Components
  1. To register a component we use @Component meta-data annotation.
  2. Component is a directive which uses shadow DOM to create encapsulated visual behavior called components. Components are typically used to create UI widgets.
  3. Component is used to break up the application into smaller components.
  4. Only one component can be present per DOM element.
  5. @View decorator or templateurl template are mandatory in the component.
Directive
  1. To register directives we use @Directive meta-data annotation.
  2. Directive is used to add behavior to an existing DOM element.
  3. Directive is use to design re-usable components.
  4. Many directives can be used per DOM element.
  5. Directive doesn't use View.
Sources:
http://www.codeandyou.com/2016/01/difference-between-component-and-directive-in-Angular2.html

Comments

Popular posts from this blog

Bootstrap Breakpoints