select in ng-option does not update

Aditya Sethi picture Aditya Sethi · Sep 19, 2014 · Viewed 9.7k times · Source

I have the list of data that is coming from backend and I want to update the select value in the view which is not happening for some reason.

I tried ng-selected that does not works efficiently, sometime the model is update spmetimes not.

here is my code, can someone help?

    <div class="listitem" ng-repeat="d in data">
        {{d.name}}: 
        <select 
            ng-model="d.option"                 
            ng-options="d.name for d in options"></select>
    </div>

Controller

var myApp = angular.module('myApp', []);
myApp.controller("SomeController", function($scope) {
    $scope.options = [{
        "id": "id1",
        "name": "p1"
    }, {
        "id": "id2",
        "name": "p2"
    }];
    $scope.data = [{
        "name": "data1",
        "option": {
            "id": "id1",
            "name": "p1"
        }
    }];
});

http://jsfiddle.net/gFCzV/58/

Answer

Satpal picture Satpal · Sep 19, 2014

You need to use select as label group by group for value in array track by trackexpr, Read DOCs

ng-options="option.name for option in options track by option.id"

DEMO, However note this will not work in Angualrjs 1.1