0

I have data coming from an array of objects that each have 3 properties:

enter image description here

This code is put into a scope variable so that it can be used on the view.

            angular.forEach(result.updatedItems, function (attr) {
                $scope.suppList = attr.name;
                var test = "";
            });

I am now trying to access this list of text values and put it in a dropdown menu:

<ul class="dropdown-menu" style="width:100%">
     <li data-ng-repeat="name in suppList track by $index" style="width:100%">{{name}}</li>
</ul>

But the results that drop down only show the 1st letter of the text that is supposed to be displayed:

enter image description here

What am I doing wrong and how do I fix it?

1 Answer 1

1

You are looping over a string instead of an array... do following changes:

CONTROLLER: Remove the loop angular.forEach and just bind the whole list to the $scope

$scope.suppList = result.updatedItems;

HTML: loop over the list with ng-repeat

<ul class="dropdown-menu" style="width:100%">
     <li ng-repeat="supp in suppList track by $index">{{supp.name}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.