Note that there are some explanatory texts on larger screens.

plurals
  1. POng-select weird behaviour
    primarykey
    data
    text
    <p>I have an issue I have trouble understanding and maybe some can enlight me on the "why".</p> <ol> <li><p>I retrieve a user from backend, let's say it looks like that:</p> <p>$scope.user { id:1, status:{ id:1, label:test } }</p></li> <li><p>I retrieve the list of all statuses from backend</p> <p>$scope.statusList = [{ id:1, label:test }, { id:2, label:toro }]</p></li> <li><p>I want to display a select input, containing the list of statuses and preselected with the user status</p></li> </ol> <p>On my template, I have the following:</p> <pre><code>&lt;select ng-model="userStatus" ng-options="status.label for status in statusList"&gt;&lt;/select&gt; </code></pre> <p>In my controller, I have tried the following</p> <p>Case 1: preselection working</p> <pre><code>function findObject(listObject, Object){ for(var i in listObject){ if(listObject[i] == Object) {return listObject[i]}; } return listObject[0]; } $scope.userStatus = findObject($scope.statusList, $scope.user.status); </code></pre> <p>Case 2: not working</p> <pre><code>$scope.userStatus = $scope.user.status </code></pre> <p>Case 3: not working</p> <pre><code>$scope.userStatus = {id:2,label:toro} </code></pre> <p>Case 4: not working</p> <p>on my template, I put the following directly</p> <pre><code>&lt;select ng-model="user.status" ng-options="status.label for status in statusList"&gt;&lt;/select&gt; </code></pre> <p>Why case 2 and case 3 won't preselect the select box??? And more importantly, case4 would be really useful to edit a user without copying everthing in a new variable, so why wouldn't it work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload