Managing $scope inheritance
Scopes in AngularJS are bound to the same rules of prototypical inheritance as plain old JavaScript objects. When wielded properly, they can be used very effectively in your application, but there are some "gotchas" to be aware of that can be avoided by adhering to best practices.
Getting ready
Suppose that your application contained the following:
(app.js)
angular.module('myApp', [])
.controller('Ctrl', function() {})
(index.html)
<div ng-app="myApp">
<div ng-controller="Ctrl" ng-init="data=123">
<input ng-model="data" />
<div ng-controller="Ctrl">
<input ng-model="data" />
</div>
<div ng-controller="Ctrl">
<input ng-model="data" />
</div>
</div>
</div>How to do it…
In the current setup, the $scope instances in the nested Ctrl instances will prototypically...
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime