Stack Exchange
how to Set Selected multipal option in angular
**in select box set selected multipal value **
This is my html
<div class="form-group">
    <label for="category">Category</label>
    <select data-placeholder="Choose a Category..."
            ng-model="store.category"
            class="standardSelect chosen-select" 
            id="select2-js-example-basic-hide-search-container"
            multiple="">
        <option ng-repeat="categorie in categories "
                ng-selected='preData.category.indexOf(categorie.id) !== 1'
                ng-value="{{ categorie.id }}">
          {{ categorie.category_name }}
        </option>
    </select>
</div>

**In this image category is multipal **


Please help me !

Are you using Select2? Please post the relevent excerpts from your code.

from controller i return
$rootScope.categories=data.data.data;

can u give me reated example ?

Describe the problem.  Tell us what the expected behavior should be. Tell us what the exact wording of the error message is, and which line of code is producing it. Put a brief summary of the problem in the title of your question.

can you share more code? and you can set some value in preData.category so its automatically set as selected

Hello I have checked your code and it seems like you want to show some option which is by default selected.
you have write following code: 
<div class="form-group">
                <label for="category">Category</label>
                <select data-placeholder="Choose a Category..." ng-model="store.category" class="standardSelect chosen-select"  id="select2-js-example-basic-hide-search-container" multiple="">
                    <option ng-repeat="categorie in categories " ng-selected='preData.category.indexOf(categorie.id) !== 1'  ng-value="{{ categorie.id }}">{{ categorie.category_name }}</option>
                </select>


Here you no need to write ng-selected='preData.category.indexOf(categorie.id) !== 1' line if you want to show some option selected by default then you just need to create an array of id, in your case it may be category.id after that just assign that array to ng-model and angular will show that option as selected.

but i have array for selected multipal category so how to set array in ng-model ?

Okay, which things were stored in "preData.category" variable?
I think this contains array of id which you want to show as selected Right? if yes then you just need to store preData.category id into ng-model variable from controller and things will be done

What changes you have done in your code?  Could you please pass it to me both controller and html code so i can understand it better way and guide you

And you can check on https://docs.angularjs.org/api/ng/directive/select
url under multiple select option just modify "multipleSelect" scope variable of controller with some initial value like ["option-1", "option-2"] then you will see both option are by default selected.
