Angular 2 Interview question and answer
What is the difference between
What is the difference between
@Component and @Directive in Angular?
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.
Sources:
http://www.codeandyou.com/2016/01/difference-between-component-and-directive-in-Angular2.html
Comments
Post a Comment