0

I have data as :

selected  : { id : <string,a task id>, description = <string> };

tasks = [ {  id : 'a', value : 'Apple' }, { id : 'b', value : 'Ball' }, 
// more items;
];

now i want to use select2 such as variable bind to select2 should contain only the id, not the whole object

so if i select Ball, the selected should be { id : 'b', description : 'some_desc' }

<ui-select ng-model="selected.id">
            <ui-select-match placeholder="select name ">{{ $select.selected.value }}</ui-select-match>
            <ui-select-choices repeat="type in tasks | filter: $select.search">{{type.value}}</ui-select-choices>
          </ui-select>

How do i achieve to have only string as selected value not the whole object.

EDIT : here is the example plunker http://plnkr.co/edit/onmP7FKIa7MpXsRnH025?p=preview

In which selected.sel is an object not a string. i want selected.sel should be a string always that is the code of conntry

1 Answer 1

1

just use in your repeat:

country.code as country in countries

should do the trick.

from your example

<ui-select ng-model="selected.sel">
    <ui-select-match placeholder="Select or search a country...">
      {{$select.selected.name}}
    </ui-select-match>
    <ui-select-choices repeat="country.code as country in countries | filter: $select.search">
       <span ng-bind-html="country.name | highlight: $select.search"></span>
       <small ng-bind-html="country.code | highlight: $select.search"></small>
    </ui-select-choices>
 </ui-select>

and if not, you should switch to the new ui-select directive, since select2 would be discontinued.

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.