1

Can anyone help me, how to show 'name' in ng-options for following structure.

"systems": {
    "android": {
      "name": "Android"
    },
    "ios": {
      "name": "iOS"
    },
    "web": {
      "name": "Web"
    }
  },

1 Answer 1

1

For structure:

$scope.systems =  {
    "android": {
      "name": "Android"
    },
    "ios": {
      "name": "iOS"
    },
    "web": {
      "name": "Web"
    }
  };

you can do it like this:

 <select ng-model='system' ng-options='key.name as value.name for (key, value) in systems'></select>

 Selected Value = {{system}}

If you have to have this structure:

$scope.systems = 
{
  "systems": {
    "android": {
      "name": "Android"
    },
    "ios": {
      "name": "iOS"
    },
    "web": {
      "name": "Web"
    }
  };

then I would do it with ng-repeat (I don't see the other way):

 <select ng-model='system' ng-repeat='(key, values) in systems'>
      <option ng-repeat='(k,v) in values' ng-bind='v.name'></option>
    </select>

 Selected Value = {{system}}

I hope it helps :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.