This small point is very important when considering the complexities of sphere inheritance.
egghead.io the video "The Dot" has a really good overview, as well as this very popular question: What are the nuances of prototype / prototype inheritance in AngularJS?
I will try to summarize it here:
Angular.js uses the inheritance scope to allow a child scope (e.g., a child controller) to see the properties of the parent scope. So, let's say you had a setup like:
<div ng-controller="ParentCtrl"> <input type="text" ng-model="foo"/> <div ng-controller="ChildCtrl"> <input type="text" ng-model="foo"/> </div> </div>
( Play on JSFiddle )
First, if you launched the application and typed it into the parent input, it will update to reflect it.
However, if you edit the area of ββthe child, the connection to the parent is now disconnected, and the two are no longer synchronized. On the other hand, if you use ng-model="baz.bar" , the link will remain.
The reason this happens is because the child region uses prototypal inheritance to find the value, so until it is never set on the child, it will be deferred to the parent region. But, once it is installed, it is no longer looking for a parent.
If you use an object ( baz ) instead, nothing will ever be set in the scope of the child, and inheritance will remain.
For details on details see https://stackoverflow.com/a/3129/
OverZealous Jul 12 '13 at 5:11 2013-07-12 05:11
source share