0

I am not sure how to phrase the question, so please forgive me if it's wrong. What I am trying to do is to retrieve the name from the array, for example :

enter image description here

The array look like this, and i want to retrieve just the "NAME" alone. Is that possible? PS: I want to retrieve from all ( eg. i got 50 counts, i want to retrieve all 50 names )

To add on, i have it stored like this : Thanks for any help in advance !

            $http({
                    method: 'GET',
                url: 'url'
                    }).then(function successCallback(response) {
                        $scope.exhibitions = response.data.SrchResults;

                    }, function errorCallback(response) {
                        console.log(response);
                    });
2
  • If you want only one then you can use $scope.exhibitions[0].ICON_NAME Commented Oct 8, 2018 at 6:48
  • From all of them Commented Oct 8, 2018 at 6:48

2 Answers 2

1
for (var i = 0; i < $scope.exhibitions.length; i++){
    if (i > 0){
        alert($scope.exhibitions[i].NAME);
    }
}

Try putting this code at the line after

$scope.exhibitions = response.data.SrchResults;

In order to display them. Try this

<div ng-repeat="exhibition in exhibitions">
    <span ng-if="exhibition.NAME">{{ exhibition.NAME }}</span>
</div>

The code is untested though. Feel free to adjust where it needs.

Sign up to request clarification or add additional context in comments.

7 Comments

May i ask how do you store it so i can display ?
What do you mean by "store it"?
Uhh, cause this is alerting which is showing a pop up box, i am trying to display it like in a table. So do i like create an empty array to store it ?
You can use your variable "$scope.exhibitions" in the view. To display them, you can use ng-repeat. See docs.angularjs.org/api/ng/directive/ngRepeat
I am trying to display just the name, not all the information in it
|
1

Bit of ES6 here.

JS

var srchResults = response.data.SrchResults;
var [first, ...exhibitions] = srchResults;
$scope.exhibitionNames = exhibitions.map(item=>item.NAME);

HTML

<div ng-repeat="exhibitionName in exhibitionNames">
    <span ng-if="exhibitionName">{{exhibitionName}}</span>
</div>

Hope it will help somebody else. :)

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.