0

Following is my code extract

   <select
        ng-init="joinedStatus=0"
        ng-options="joinstat.name for joinstat in joined track by joinstat.id"
        ng-selected="joinedStatus==joinstat.id"
        ng-model="joinedStatus">
        <option>{{joinedStatus}}</option>
   </select>

But still there is no default option selected.

joined is defined as:

$scope.joined=[{id:0,name:'No'},{id:8,name:'Yes'}];

1 Answer 1

1

You should not provide <option> inside select since ng-options will add the options from specified array.

ng-selected is of no use. Remove it too.

So, this will work

<select ng-init="joinedStatus=joined[0]"
        ng-options="joinstat.name for joinstat in joined track by joinstat.id"
        ng-model="joinedStatus">

</select>

Since we have initialized the model with 0th array element. You will see this selected in the select.

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

1 Comment

Note that it is not recommended to use "ng-init" in such cases. It would be better to initialize "joinedStatus" in you controller.

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.