0

Here I want to retrieve some feilds from the json data. This is my json data:

[{"ipaddress":"10.132.32.212","id":"18"},    
 {"ipaddress":"10.132.32.213","id":"19"}]

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>

	<div ng-app="lostsysApp" ng-controller="mainController">
	<ul>
  <li ng-repeat="x in ipaddress | orderBy:'id'">
    {{ x.ipaddress + ', ' + x.id }}
  </li>
</ul>
</div>

<script>

var app = angular.module('lostsysApp', []);
app.controller('mainController', function($scope, $http) {


$http({ method : "GET",
    url : "http://10.132.32.218:8080/DBtoWeb/services.jsp",
    Accept: "application/json"

    }).then(function mySucces(response) {
      $scope.myData=response.data;
      }, function myError(response) {
        //Second function handles error
        $scope.myData = "Something went wrong";
    
  });
});

</script>

</body>

</html>

2 Answers 2

0

I think you mean

  <li ng-repeat="x in myData | orderBy:'id'">

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

4 Comments

in the above json data i need the values of ipaddress and id
Yep, and presuming response.data does contain the data you say it does (the JSON array), then the above code will work.
By the way assigning the string "Something went wrong" to myData is not a good idea, as you are asking the same scope field to contain two different types of data (an array or a string). You should assign the error string to some other field.
The code is correct, but something else is going on. Put a javascript breakpoint at the line $scope.myData=response.data; and inspect the response.data. BTW, it's unhelpful to say "the code will not work" without saying what fails and how. Is there an error? What happens exactly? Try to problem solve this a bit yourself.
0

You can checkout this Plunker

  <div ng-app="lostsysApp" ng-controller="mainController">
    <ul>
      <li ng-repeat="x in myData | orderBy:'id'">
        {{ x.ipaddress + ', ' + x.id }}
      </li>
    </ul>
  </div>

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.