1

I have an array of strings, that are account numbers. When a record in a table is clicked i provide a modal to update the record and one of the fields is account number. This displays and some what correctly but seems to loss its two way binding with vm.accountNumber but also does show the value that the model is.

vm.accountNumber always has a value that is set when the table row is being clicked for editing. It just never makes it to the select despite the model. I suspect im losing the two way link and it is creating its own variable for the model.

  <select class="ui search fluid selection dropdown" id="accountSearch" ng-model="vm.accountNumber">
          <!--ng-options="account for account in vm.accounts.slice(1)">-->
          <option ng-repeat="account in vm.accounts | limitTo: vm.accounts.length : 1" value="account" ng-selected="account == vm.accountNumber">{{account}}</option>
  </select>

Here is a snippet of the accounts array. 0:"-" 1:"0001" 2:"0002" 3:"0003" 4:"0004"

1 Answer 1

3

I would say just use ng-options directive instead of ng-repeating option

<select class="ui search fluid selection dropdown" 
    id="accountSearch" ng-model="vm.accountNumber"
    ng-options="account for account in vm.accounts">
</select>

Demo Plunkr


Though I'd like to point out your problem was with option value attribute,

you should change

value="account"

to

value="{{account}}"
Sign up to request clarification or add additional context in comments.

12 Comments

While i agree i like the ng-options, you can see commented out i attempted the options as well and then even tried doing a ng-selected expression. Neither worked. The value didnt change anything but thanks :)
may I know what is vm.accounts.slice(1)? can you please also add vm.accounts json in question?
That is just skipping the first result which is "-". Updated question with array.
@user1552172 don't do that slice operation over there. do it on controller side, it will remove one item per digest cycle..and as per your dummy data I can say after 5 digest cycle nothing will be there..
@user1552172 added plunkr, could you please check it?
|

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.