Search code examples
angularjsdropdownangularjs-ng-options

Not able to load JSON data into DropDownList in AngularJS


I'm getting blank data while loading JSON data into Dropdown using Angular ng-options.

My JSON Values

"tagFormat": {
        "displayText": "Tag Format",
        "options": [{
            "value": "js",
            "name": "JS"
        }, {
            "value": "vast",
            "name": "VAST"
        }]
    },

HTML View

<div class="select_padding">
    <select class="form-control" ng-options="otf.value as otf.name for otf in details.tagFormat.options">
         <option>Select Tag Format</option>
    </select>
</div>

here details is my scope variable.

how to get these data and also next time I need to use selected value. so Do I need to bind with ng-model ?

Thanks


Solution

  • Here is the working code:

        <select class="form-control" ng-options="item as item.name for item in details.tagFormat.options track by item.value" ng-model="selected">
             <option value="">Select Tag Format</option>
        </select>
    

    In $scope.selected you read the selected item.

    Check this example on Codepen: http://codepen.io/beaver71/pen/Vexwmr