Setting default value in select drop-down using Angularjs

前端 未结 10 1151
囚心锁ツ
囚心锁ツ 2020-12-03 05:24

I have an object as below. I have to display this as a drop-down:

var list = [{id:4,name:\"abc\"},{id:600,name:\"def\"},{id:200,name:\"xyz\"}]
10条回答
  •  被撕碎了的回忆
    2020-12-03 05:32

    Problem 1:

    The generated HTML you're getting is normal. Apparently it's a feature of Angular to be able to use any kind of object as value for a select. Angular does the mapping between the HTML option-value and the value in the ng-model. Also see Umur's comment in this question: How do I set the value property in AngularJS' ng-options?

    Problem 2:

    Make sure you're using the following ng-options:

    
                            
        
    提交评论

提交回复
热议问题