select in ng-option does not update

10,031

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

Share:
10,031
Aditya Sethi
Author by

Aditya Sethi

I am a Front End Engineer who has worked on several technologies and has built applications on IOS platform, Blackberry, Java, ROR etc. Currently envolved in learning angularjs and building applications using this platform which is totally amazing. Also I have worked on charting libraries. I want to learn as much as I can.

Updated on June 27, 2022

Comments

  • Aditya Sethi
    Aditya Sethi about 2 years

    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/