1

I use angularjs with ui-select (https://github.com/angular-ui/ui-select/)

I have this code:

<ui-select tagging="addTagging" tagging-tokens="ENTER" ng-change="sourceChanged()" ng-model="sender" theme="bootstrap" sortable="true" ng-disabled="disabled">
    <ui-select-match>{{$select.selected.name}}</ui-select-match>
    <ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
        {{item.name}}
    </ui-select-choices>
</ui-select>

Inside the sourceChanged function I want to know the index of the selected item.. Now i just have the value (scope.sender)..
I can search for the value in places array but it's not good enough for me because there is a chance that there will be several items with the same value...

Any idea?

Thanks :)

1 Answer 1

2

You have wrong repeat expr.

<ui-select-choices data-id="$index" repeat="item.name as item in places | filter:$select.search">
        {{item.name}}
    </ui-select-choices>

You are telling ui-select, iterate trought places and bind item.name inside model, change it to

<ui-select-choices data-id="$index" repeat="item in places | filter:$select.search">
        {{item.name}}
    </ui-select-choices>

It will bind complete item object to ngModel , so you have original item from array of places.

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

1 Comment

if you want index you jast have to call $scope.places.indexOf($scope.sender) , it will return index inside original array

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.