What is the difference between directive and component?

7

It seems that in newer versions, in addition to the directive method, Angular 1 also has a method called component .

I would like to understand the main differences between one and the other.

What are the main differences between directive and component ?

When should I use component instead of directive ?

Before you ask me this: The documentation page is in English, I would like an explanation in Portuguese, which for me is easier.     

asked by anonymous 13.03.2017 / 19:21

2 answers

2

The Component is a special directive, it was created to supply and correct problems that the directive has when you want to create a html component that has a controller and a html itself, these problems would be: no bindings, no isolated scope and ambiguities generated by the specifications of the link and attribute type directives.

You should use a Component: Whenever you want to create an isolated html component (it replaces the creation of an html with ng-controller binding from a controller).

You should use a Directive: Only when you want to create an attribute that performs some DOM manipulation javascript or simple manipulation of information.

    
13.03.2017 / 19:42
0

The component is similar to the directive, but it is easier to configure and comes with the tendency to ease the projects from Angular 1.x to Angular 2. However, the components are only limited to attributes.

    
13.03.2017 / 20:45