0

I need to add a class to the options produced using ng-options. The options are being listed from a Svc and I'm also needing to insert a class being called from that object. I've seen other threads that show how to do this, but they all referencing a boolean from the object and i just need to call string as the class.

Can anyone lend a hand. I know it's going to be something simple.

<select class="report-user" ng-change="testchange(curTest)" ng-model="curTest" ng-options="value.LinkToken as value.Name for value in tests" options-class="{ 'minor-account' : ALLOWED_FOR_MINOR}" required>

Here is the object called from the Svc:

    "Employees": [
    {
        "ExtensionData": {},
        "CanChangeNotices": true,
        "CanEditData": true,
        "CanRefillScripts": true,
        "CanRunReports": true,
        "CanViewData": true,
        "DateOfBirth": "/Date(1448949600000)/",
        "EmployeeClass": "ALLOWED_FOR_MINOR",
        "EmployeeMessage": "You have been given access to this employee's information.",
        "EmployeeStatus": "Allowed For Minor",
        "EmployeeTypeId": 3,
        "EmployeeTypeName": "Trainee",
        "FirstName": "Sqaweb1",
        "HasAccount": false,
        "IsAuthorized": false,
        "LastName": "Test",
        "LinkToken": "XxXxXxXxXxXxXxXx"
    },

I'm able to get it to insert names into the option list and associate linkToken, but I just need to make "EmployeeClass" value be the actual class="ALLOWED_FOR_MINOR" (or other values returned from the service) that is actually rendered on the element attribute.

Here's where the controller provides the items for the ng-options.

$scope.tests = [];
$scope.tests = $scope.user.Employees.map(function(item){
    return {
        'Name':item.FirstName,
        'LinkToken':item.LinkToken

    }});

$scope.tests.splice(0, 0, {
    'Name': $scope.user.FirstName,
    'LinkToken': $scope.user.LinkToken
});
$scope.curTest = $scope.tests[0].LinkToken;
billy_comic
  • 867
  • 6
  • 27
  • never used `options-class` but would try `options-class="{{EmployeeClass}}"` – charlietfl Oct 23 '15 at 20:12
  • Seems `optionsClass` is a custom directive that was posted in another [SO question](http://stackoverflow.com/a/15278483/3120193). – Michel Oct 23 '15 at 20:18
  • Yeah, I saw that one and have tried to use it, but can't get it to work. it's creating a boolean from the object and all I need is to write the value from the object as the class, no luck. Thanks – billy_comic Oct 23 '15 at 21:57

0 Answers0