0

js-fiddle: https://jsfiddle.net/4z5ufbuu/

I'm trying to select a value from an array I have via a select option. here are my options:

$scope.categories = [
        { type: "Web Application", cssClass: "webApplication" },
        {  type: "Unity", cssClass: "unity" },
    ];

$scope.filterValue = "";

I have it so the select displays the "type" but I want the "filterValue" to represent the cssClass.

I have seen this page:

https://stackoverflow.com/a/12384319/9132034

but dont really understand this answer:

obj = { '1': '1st', '2': '2nd' };

<select ng-options="k as v for (k,v) in obj"></select>

guidance would be absolutely perfect or even the solution but that is up to you :)

  • Read the official angularjs documentation. That should clear your doubts: https://docs.angularjs.org/api/ng/directive/ngOptions. – NiK648 Feb 15 '18 at 17:56

1 Answers1

0

You need to update your ng-options to be:

ng-options="item.cssClass as item.type for item in categories track by item.cssClass"

This is saying to use item.cssClass as the value while displaying type as the label

it is documented in the angularjs official documentation https://docs.angularjs.org/#ngOptions-info

Edit: updated JS Fiddle https://jsfiddle.net/4z5ufbuu/4/

AnthW
  • 523
  • 5
  • 19