Shamoon Shamoon - 10 months ago 46
Javascript Question

ng-model isn't updating when I change a select option

I have a select box with some

, but it's not updating the
when I select an option. I have a fiddle up at to view the source.

My HTML is

<div ng-controller="MyCtrl">
PARENTID: {{ parent_id }}
<select ng-model="parent_id" ng-options=" as project.groupingName for project in projects track by $index"></select>

and when I select something, the
doesn't update. What am I doing wrong?


Updated Fiddle :

Your projects array of objects does not contain id so replaced it with gid


<select ng-model="parent_id" ng-options="project.gid as project.groupingName for project in projects"></select>

Another mistake: as shouldn't be used with track by

Refer AngularJs Docs -

Be careful when using select as and track by in the same expression