Joined September 2013
·

kpko

devmetal
·
Germany
·
·

Hi,

you shouldn't bind directly to the key object in ng-repeat, because this object is not the original object from your array. That's a caveat when you are binding to a primitive array.

ng-repeat creates a new scope for each iteration. Given we have an expression like

ng-repeat="item in items" 

where items is defined as ["a", "b", "c"], AngularJS projects these values into new objects, so you basically have objects like { item: "a" }, { item: "b"} and { item: "c" } in your child scope in ng-repeat. If you use ng-model="item", you are binding to this item on the new, projected object now and not to your original array.

You can however bind to a property: Change the ng-model="item" to something like ng-model="item.name" (http://jsfiddle.net/ya4ohauk/) and the binding should work as expected.

[
  { name: "a" },
  { name: "b" },
  ...
]

or in your case

[
  { name: "Campus 1" },
  { name: "Campus 2" }
]

If you need a flat array of these values, you can use JavaScripts map function to get these:

var flatArray = $scope.campuses.map(function(campus) {
  return campus.name;
});
Achievements
49 Karma
0 Total ProTip Views