2

my html code;

            <!doctype html>
            <html ng-app ng-controller="peopleController">
              <head>
                <script src="js/angular.min.js" type="text/javascript"></script>
                <script>
                function peopleController($scope){
                        $scope.people = [
                            { name : "aa" , age : 14 },
                            { name : "ss" , age : 11},
                            { name : "dd" , age : 12},
                            { name : "ff" , age : 16},
                            { name : "gg" , age : 13}
                        ];

                        $scope.keys=(function(obj){
                            var keys = [];
                            for(var key in obj){
                                console.log(obj);
                                if(obj.hasOwnProperty(key)){ keys.push(key);}
                            }
                            return keys;
                        })($scope.people[0]);
                    }
                </script>
                <title>aasss</title>
              </head>
              <body >
              <select ng-model="aaa">
                <option ng-repeat="x in keys" value="{{x}}">{{x}}</option>
              </select> 
              </body>
            </html>

generated html part for select element;

            <select ng-model="aaa" class="ng-pristine ng-valid">
                <option value="? undefined:undefined ?"></option>
                <!-- ngRepeat: x in keys -->
                <option ng-repeat="x in keys" value="name" class="ng-scope ng-binding">name</option>
                <option ng-repeat="x in keys" value="age" class="ng-scope ng-binding">age</option>
            </select>

when I remove ng-model="aaa" attribute from select element the problem does not appear. what could be the problem?

1
  • try to set up a plnkr.co Commented Nov 1, 2012 at 16:55

1 Answer 1

4

You should not be using ng-repeat in select, review select doc. select has its own comprehensions mechanism. Also, not sure why you have 2 ng-repeat in your selector. Seems like you might want to encapsulate the 2 sets of keys.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.