view raw
Suny Saju Suny Saju - 10 months ago 39
AngularJS Question

how to assign value to select tag in angularjs

I have a select box. For updating I retrieve data from database. So how can I assign retrieved values to select options?

For example:

$scope.options = [{ name: "Select Gender", id: 0 }, { name: "Male", id: 1 }, { name: "Female", id: 2 }];

These are the options. I want to assign
to the select box. How can I do this?

This is the plunk I created for reference.


Please look at the Plunker based on your one.

First of all, you have to do:

$scope.selectedOption = $scope.options[1];

Then ng-options directive should look like:

data-ng-options=" as for o in options track by"