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 AngularJS Basics (1.x) Controllers and Scope Understanding Scope In Angular

Is the $scope set up in Angular just like the scope of variables and functions in plain JavaScript?

Great video but just to make sure I understand it, is there any real difference between how Angular controllers inherit $scope than functions and objects in plain old JavaScript inherit from their parents and pass down to their children (if the children request that data and don't overwrite it). A 'trickle down' affect?


Having spent some time learning about object prototypal inheritance and the scope system in Js, Angular doesn't seem to be as hard to get my head around as I first feared :)

3 Answers

Andrew Kiernan
Andrew Kiernan
26,892 Points

Hey Dave,

$scopes in Angular are prototype chains just like you're thinking. The top level is $rootScope, and all $scopes in your controllers inherit from that. Then any child $scopes you define create another level of $scope inheritance, but they are plain old prototypal inheritance!

-Andrew

Andrew Kiernan
Andrew Kiernan
26,892 Points

Hey Sua,

When you add the ng-app directive, you are declaring that your app starts at the tag specified, and also ends at its corresponding closing tag. So if you add the ng-app directive the the 'html' tag, your app is bootstrapped for the entire page, between the opening and closing 'html' tags.

-Andrew

within the html, an ng-app is injected with the ng-app attribute, but does it end at the </div> tag?