F
F
faragly2015-01-03 10:08:40
Angular
faragly, 2015-01-03 10:08:40

How to set select values ​​on load in angularjs array?

Good day, dear developers! Yes, judging by the title, not everything is clear, I don’t know how to formulate the question correctly, I made an example on jsfiddle . In the example, {{options}} contains the GROUP_DEFAULT_TASK value, and that's only because it's explicitly set in the script:

var defaultIndex = 0;
  $scope.rightsData.tasks.forEach(function(task, i) {
    if(task.id == $scope.rightsData.default)
      defaultIndex = i;
  });
    $scope.options = {};
  $scope.options.GROUP_DEFAULT_TASK = $scope.rightsData.tasks[defaultIndex].id;

But I'm interested in how to make it show immediately when loading in options
{"GROUP_DEFAULT_TASK":"132","TASKS_3":"133","TASKS_7":"134"}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-01-03
@Nc_Soft

Similarly, when initializing, set initial values ​​for other selects.

S
Sergey, 2015-01-03
@TsarS

I didn't quite understand the problem. Something like ng-init? As here

<select ng-init="somethingHere = options[0]" ng-model="somethingHere" ng-options="option.name for option in options"></select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question