We can inherit a scope (or I may think of it as the usual outer scope / inner scope scenario):
Same controller: https://jsfiddle.net/fk4hzvxw/
Different controllers: https://jsfiddle.net/fk4hzvxw/1/
<div ng-app="myApp">
<div ng-controller="hihi">
<div ng-init="ha = 42"></div>
<input type="text" ng-model="ha"> {{ ha }}
<div ng-controller="hello">
<input type="text" ng-model="ha"> {{ ha }}
</div>
</div>
</div>
So I think, it is said that, controller "hihi" creates a scope, and controller "hello" creates also a scope, and inherits the scope created by controller "hihi". (Or I might think of it as just outer scope and inner scope like in a traditional program -- is this a correct way to think about it?)
We can type into the first input box, and all values on the screen update to the same value. However, when we type into the second input box, then the second variable seems to "take off as its own". Now there are 2 variables ha
, one in the outer scope, one in the inner scope, as we type into the 2 input box, they affect only its own scope's variable.
How should we think about this? In traditional programming, this won't happen. Also, what are the implications of this?