2

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.

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

I thought it for a while then tried to set the value as int like <option value=1> which not worked as expected! Thanks.
tumar uchit hbe ngOptions use kora . esob kaj ngOptions handle kore dibe @Badhon
Ok, I will. asole ei dropdown gula always 2 ta value hold korbe, tai vabci inline diye dei. Thanks.
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.