I have a JSON object that holds the names of different dropdowns. It looks something like this -
$scope.dropdowns = {
"dp1" :{},
"dp2" :{}
}
The objects dp1
and dp2
correspond to their respective dropdown menus. These objects will be used by the dropdown menus to populate their options.
Next, I have a function for making a REST call like this -
$scope.getData = function(category, type) {
var params = { "dp1" : category, "dp1__type": type};
PromiseService.getPromiseData("GET", "/api/get_data/?" + $httpParamSerializer(params)).then(function(response) {
$scope.dropdowns.dp1= response;
});
}
I am able to successfully assign the response data to $scope.dropdowns.dp1
. The response object looks like this-
{ "id" : 1, "name" : "john" }
Finally, my dropdown menu code looks like this -
<select id="d1" ng-model="d1">
<option ng-repeat="opt in dropdowns.dp1" t>{{opt.id}}_{{opt.name}}</option>
</select>
I want to populate the dropdowns
JSON object based on the response, which I have successfully done. Then, I want to access the sub-object within dropdowns
and use ng-repeat
on it to populate the options for the dropdown menu.
The current implementation of ng-repeat
is resulting in undefined undefined
.