0

I have the following array in angularjs and want to populate the Select List.

types: {
  data: {
    result: [
      {
        Item: Default Group
        Val: 1
      }
    ]
  }
}

I have tried the following code but no result

<div ng-controller="dtaCtrl">
   <select class="form-control" ng-repeat="lop in types">
      <option>{{lop.data.result.Item}}</option>
   </select>
</div>
The.Bear
  • 5,621
  • 2
  • 27
  • 33
user3513192
  • 97
  • 2
  • 14
  • It **sounds** like you're looking for `{{lop.result[0].Item}}`. That's assuming you truly want `lop` to be equivalent to `data`... – Obsidian Age Feb 16 '17 at 23:58
  • types is not an array, so using ng-repeat to iterate on types doesn't make much sense. `lop.data.result` **is** an array, and an array doesn't have an Item property, so `lop.data.result.Item` doesn't make sense either. – JB Nizet Feb 17 '17 at 00:13

1 Answers1

0

ng-repeat needs to be an array - https://docs.angularjs.org/api/ng/directive/ngRepeat

try:

vm.types = [{
            data: {
                result:
                   [{
                      Item: 'Default Group',
                      Val: 1
                   }]
                 }
           }];

And then use:

<select class="form-control" ng-repeat="lop in vm.types track by $index">
    <option>{{lop.data.result[$index].Item}}</option>
</select>
IKramer
  • 61
  • 8
  • Dear friend: I am getting this data from a web service I designed. In last example I had made a mistake after setting it up, I got the following result, Yet it is not producing the output; – user3513192 Feb 17 '17 at 00:32
  • types: { data: [{"Item":"Default Group","Val":"1"}] status: 200 headers: null config: { method: POST ......................... – user3513192 Feb 17 '17 at 00:32
  • The problem with the repeat is that `types` is not an array. If you want to repeat just the inner array, can you do `ng-repeat="lop in types.data` and bind to `{{lop.Item}}` – IKramer Feb 17 '17 at 00:42