Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

brandonlind2
brandonlind2
7,823 Points

difference between directive and controller?

In angular.js what is the difference between a directive and a controller? I'm a bit confused to what exactly the difference is, they both seemed to be used to add content to a page, controllers just seem to have scope. i understand the need to use both in a website, why not just use controllers only. maybe i'm not understanding something correctly?

1 Answer

David Bath
David Bath
25,940 Points

They have different purposes. As I understand it, directives act as "hooks" in the HTML that allow you to attach behavior/functionality to elements. Controllers are functions that contain application logic. So while directives are more closely related to the "view" of MVC, controllers are, well, the "controllers" in MVC. That's the basic difference.