简体   繁体   中英

setting value in select drop down not working

I am new to Angular and we are rewriting our app in it. I can't seem to figure out something very basic. I am trying to replace the option value to the Id after the data gets fetched. I created a jsbin to just do it for static data, but I can't seem to get the Id set to the value in the option.

Can anyone lend a quick hand? Thanks.

http://jsbin.com/dazolelu/1/edit

remove the .id from proj

<select ng-model="selectedProject" ng-options="proj as proj.Name for proj in projects"></select>

  {{selectedProject.Id}}

here is the url : http://jsbin.com/rocajeja/1/

this is the edit url : http://jsbin.com/rocajeja/1/edit

just add this to your controller

 $scope.selectedProject= $scope.projects[0].Id;

This will tell the controller to set the default value ie $scope.selectedProject to the first project.

JsBin fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM