Search code examples
angularjsng-optionsangularjs-ng-options

ng-options with object literal data source


How do you use ng-options with a object literally where the key of the object is the value and value of object is label. I tried a few suggestions on this site but none seem to work only the default options is showing.

   $scope.interviewStatusMessages = {
        "cp": "l'attente de la réponse du candidat",
        "ca": "candidat accepté",
        "cm": "candidat modifiée",
        "cr": "candidat rejeté",
        "ea": "vous avez accepté",
        "em": "vous avez modifié, en attendant la réponse du candidat",
        "ec": "vous avez annulé",
        "ic": "terminé"
    }

I tried

<select
    ng-options="interviewStatus for (key, label) in interviewStatusMessages">
    <option value="">-- filter interviews --</option>
</select> 

Solution

  • Try doing:

      <select ng-model="selectedStatus" ng-options="key as value for (key,value) in interviewStatusMessages">
         <option value="">Select Status</option>
      </select>
    

    Here is a plunker