0

I have a json array from a json response of this nature

data {"success":true,"errorCode":0,"data":["kkkk-kkkk 1","oooo-ooooo 2"]}
  1. Item 1 is expected to be >>> kkkk-kkkk 1
  2. Item 2 is expected to be >>> oooo-ooooo 2

in angular script controller I am doing this to push the array into the html view

else if (res.status == 200) { 
    $scope.partners = []; 
    var myJSON = res.data; 
    console.log("data" + JSON.stringify(res.data));
    angular.forEach(myJSON, function (item) { 

    $scope.activities.push(item);

I want to get the json arrays to fill a dropdown of this is a challenge

<select ng-model="act" formcontrol class="ui fluid dropdown ng-untouched ng-pristine ng-valid" required>
  <option ng-repeat="a in activities" value="{{a}}">{{a}}</option>
</select>

Please assist

4
  • 1
    Why don't you assign res.data.data directly to $scope.activities? Commented Aug 17, 2018 at 13:56
  • yes that wont also solve the drop problem Commented Aug 17, 2018 at 13:57
  • What do you mean by drop problem? Commented Aug 17, 2018 at 13:57
  • this >>> <option ng-repeat="a in activities" value="{{a}}">{{a}}</option> Commented Aug 17, 2018 at 13:58

2 Answers 2

1

Actually you are iterating the wrong array, you are iterating the object instead.

Because in your code:

console.log("data" + JSON.stringify(res.data));

Will give you:

data {"success":true,"errorCode":0,"data":["kkkk-kkkk 1","oooo-ooooo 2"]}

So you need to store res.data.data in your myJSON variable, or the best would be to assign this array directly in your $scope.activities:

$scope.activities = res.data.data;

And in your HTML:

<select ng-model="act" formcontrol class="ui fluid dropdown ng-untouched ng-pristine ng-valid"  ng-options="option for option in activities"required>
</select>
Sign up to request clarification or add additional context in comments.

4 Comments

that has been done so how how I populate the dropdown with it
upon clicking the dropdown
Please show us a live demo so we can see the whole code and the issue.
0

use ng-options

ng-options="item as item for item in activities" 

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.