reflija
reflija

Reputation: 55

angularJS json getting resource?

            getTestimonials: function() {
                Requests.postData({
                        action1: 'getTestimonials'
                    }, {
                        market: "sg"
                    },
                    function(res) {
                      $scope.Testimonial = res.res;
                      console.log(res.res);
                    },
                    function(rej) {
                        console.log('rejected');
                    });
            },

enter image description here

I need to get airline name {{Testimonial}} give me :

[{"VISITORNAME":"MICHAEL","DEPARTURE":"SINGAPORE","DESTINATION":"SHANGHAI","AIRLINE":"SINGAPORE AIRLINES","TEXT":"VERY PROMPT AND EFFICIENT SERVICE!"},{"VISITORNAME":"AMY","DEPARTURE":"SINGAPORE","DESTINATION":"JOHANNESBURG","AIRLINE":"QATAR AIRWAYS","TEXT":"I LIASED THROUGH SALMA, WHO WAS EXTREMELY HELPFUL AND COURTEOUS. EVEN THOUGH I WAS OCCUPIED IN MEETINGS OVER HTE COURSE OF 2 DAYS, WE MANAGED TO COMMUNICATE PROMPTLY OVER EMAIL. ONCE, WE BEGAN TO FINALISE THE TRANSACTION SHE CONTACTED ME OVER THE PHONE"},{"VISITORNAME":"ANTHONY","DEPARTURE":"SINGAPORE","DESTINATION":"SEOUL","AIRLINE":"SINGAPORE AIRLINES","TEXT":"THIS IS MY FIRST EXPERIENCE WITH SKYLUX AND I TRAVEL A LOT FOR BUSINESS. NELLY'S TURNAROUND ON EMAILS IS VERY QUICK AND HELPFUL. OVERALL SERVICE IS 10/10."}]

Upvotes: 2

Views: 49

Answers (2)

Suraj Sharma
Suraj Sharma

Reputation: 857

convert Json to a javascript object using angular.fromJson(jsonString).

var obj = angular.fromJson(jsonString);
// obj has an array of objects, so iterate the array to get the airline name and store it in any other array or use ng-repeat to show it in the html template

$scope.airlineDetails = angular.fromJson(jsonString);

//now in the html template,
<ul>
<li ng-repeat = "a in airlineDetails">a.airline</li>
</ul>

Upvotes: 0

Ayush
Ayush

Reputation: 42440

$scope.Testimonial here is an array. Airline names are at $scope.Testimonial[i].airline where i is the index of the element you want to access.

If your view is using a loop (ng-repeat), you can do something like this:

<span ng-repeat="t in testimonial">{{t.airline}}</span>

Upvotes: 2

Related Questions