Badhon Jain
Badhon Jain

Reputation: 1007

How to set angular dropdown value dynamically?

I have a dropdown like this:

<select data-ng-model="docPropIdentityModel.Status" class="form-control">
  <option value="">-- None --</option>
  <option value="1">Active</option>
  <option value="0">Inactive</option>
</select>

I'm trying to set its value to a specific option as follows:

$scope.docPropIdentityModel.Status = 1;

I was expecting to set its value to 1, so that Active is shown as the dropdown option. But its not working.

Upvotes: 2

Views: 4000

Answers (2)

Avinash Kalola
Avinash Kalola

Reputation: 113

In angularJS you want to binding select control than use dynamic populate select control. You are using static binding so this way you can`t able to select dynamic

$scope.docPropIdentityModel.Status = [{Id:'1',Name:'Active'},{Id:'2',Name:'Inactive'}]

<select data-ng-model="docPropIdentityModel.Status" name="statuss"
        ng-options="status.Name for status in docPropIdentityModel.Status track by status.Id" required>
</select>

Upvotes: 1

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Your option's value type is string.

In order to make it selected, you have to provide a string type data.

try like this

$scope.docPropIdentityModel.Status="1";

JSFIDDLE

Upvotes: 4

Related Questions