2

i m using ui.select2 for dropdowns

Scenario i have an ajax call that return drop down values

document.dropDownDocStatuses = [
            { key: 0, value: 'All active (' + response.totalDocuments + ')' },
            { key: 1, value: 'Draft (' + response.draft + ')' }            
        ];

in html i have

<select ui-select2 class="form-control font-12px input-style3 " 
ng-model="document.dropDownDocStatus"        
ng-change="document.filterDocuments()">
<option ng-repeat="documents in document.dropDownDocStatuses"  value="{{documents.key}}">({{documents.value}})</option>  </select>

user have selected value enter image description here

Issue now when i update any value of dropdown using

  _document.dropDownDocStatuses[_document.dropDownDocStatus].value++;
                _document.dropDownDocStatuses[1].value++;

valuge gets updated but it doesnt change selected value text whereas if i click on dropdown i get changed value in dropdown enter image description here

can someone guide me how can i fix the issue, any help will be appreciated

1 Answer 1

3

i have just come across the same issues as yours, and the root cause is the ng-model field, which you should not use the "options" field to store the ng-model, try to create another field for ng-model, and you will be able to select the value.

e.g.

document.dropDownDocStatuses = [
            { key: 0, value: 'All active (' + response.totalDocuments + ')' },
            { key: 1, value: 'Draft (' + response.draft + ')' }            
        ];
document.selectedDocStatus = [];

and in HTML:

<select ui-select2 class="form-control font-12px input-style3 " 
ng-model="document.selectedDocStatus"        
ng-change="document.filterDocuments()">
<option ng-repeat="documents in document.dropDownDocStatuses"  value="{{documents.key}}">({{documents.value}})</option>  </select>

then you should be able to select the value successfully.

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

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.