Setting default value in select drop-down using Angularjs

前端 未结 10 1133
囚心锁ツ
囚心锁ツ 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:37

    This is an old question and you might have got the answer already.

    My plnkr explains on my approach to accomplish selecting a default dropdown value. Basically, I have a service which would return the dropdown values [hard coded to test]. I was not able to select the value by default and almost spend a day and finally figured out that I should have set $scope.proofGroupId = "47"; instead of $scope.proofGroupId = 47; in the script.js file. It was my bad and I did not notice that I was setting an integer 47 instead of the string "47". I retained the plnkr as it is just in case if some one would like to see. Hopefully, this would help some one.

提交回复
热议问题