4

I have select with ng-repeat:

<select class="span5 ui-select2 id="goal_{{goal.id}}" multiple="multiple">
  <option ng-repeat="counterGoal in counterGoals" value="{{counterGoal.id}}">{{counterGoal.name}}</option>
</select>

in goal model I have counter_goal_ids array like [1,2,3,4,5,6].

How can I select options that are included in goal.counter_goal_ids?

0

1 Answer 1

9

Try the following:

You can select the options by using the ng-selected attribute and a custom function in your model

ng-selected="isInGoalIds({{counterGoal.id}})"

And in your model, add a function

$scope.isInGoalIds = function(id){
    angular.forEach($scope.counter_goal_ids, function(value, index){
      if(id == value){
        return true;
      }
    });
    return false;
}
Sign up to request clarification or add additional context in comments.

1 Comment

It will not run 100*100. This is only if your goal array is the same size as your initial array. There will be total_items * goal_items iterations max

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.