What is the scope of ng-init in Angular? Here's a simple example that demonstrates my question:
<div ng-init="model = { year: '2013'}">
<a href="" ng-click="model.year = '2012'">2012</a> |
<a href="" ng-click="model.year = '2013'">2013</a>
<div>Showing {{ model.year }}</div>
<hr />
</div>
<div ng-init="model = { year: '2013'}">
<a href="" ng-click="model.year = '2012'">2012</a> |
<a href="" ng-click="model.year = '2013'">2013</a>
<div>Showing {{ model.year }}</div>
</div>
Live example available here: http://plnkr.co/edit/HkioewOzzglvFMKDPdIf?p=preview
Is seems that ng-init scope is shared among the 2 div[ng-init]
. For example, if you click on the year '2012' in either section, it changes the year
property in both sections.
Is there a way to tell angular to create a new scope for each ng-init and thereby clicking the '2012' year will only impact the section that it belongs to?