Suny Saju Suny Saju - 1 year ago 68
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.

Answer Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download