Joined November 2013
·
Posted to
ng-repeat $index for a form field array (ie add new option)
over 1 year
ago
Referencing item from ng-repeat in ng-model should still work.
<select class="form-control" ng-model="item">
<option>Select a campus</option>
</select>
Posted to
How to Become a Better Developer
over 1 year
ago
Very well written. You hit every nail on the head. Good job!
@theatlasroom Now I understand. The reason why this is happening is because ng-repeat creates a new scope for every iteration. Therefore when the item is referenced, the data is lost upon refresh. Whereas referencing it directly from the list, which is stored in the controller's scope, will keep the data in sync. Even if you were to put campuses directly in scope, this wouldn't work. Like:
This is all because of how $scope inheritance works. You can take a look at this: https://github.com/angular/angular.js/wiki/Understanding-Scopes