0

Here is the working code:

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope, $http) {
  $scope.name = 'World';

  $http({
    url: 'http://landregistry.data.gov.uk/landregistry/query', 
    headers: { 'Content-type' : 'application/x-www-form-urlencoded',
            'Accept' : 'application/sparql-results+json' },
    method: "GET",
    params: {
            query : "select * where {?s a ?o} limit 10",
            format: "json"
        }
  })

  .success(function(data, status, headers, config) {
    $scope.results = data.results.bindings;
    // this callback will be called asynchronously when the response is available 
   })

  .error(function(data, status, headers, config) { 
    // called asynchronously if an error occurs or server returns response with an error status.
  });

});

http://plnkr.co/edit/LfkIPZRsZ4QHTfq2A2vc?p=preview

My doubt is how to store for instance, all s.values in an array such that the array can be further used to populate a drop down menu without having to save the JSON output to an external file.

Thanks.

evsheino
  • 2,147
  • 18
  • 20
Ria Singh
  • 3
  • 2
  • Isn't it simple JSON processing in Javascript? And why do you think you have to "save the JSON ouptut to an external file"? Parsing the JSON will return a JSON object – UninformedUser Jun 04 '17 at 19:20
  • Okay, thanks, well, because I didn't know about JSON processing in Javascript. Can you show code example? – Ria Singh Jun 04 '17 at 19:24
  • var json = JSON.parse($scope.results); Added this to html: {{json.value}} – Ria Singh Jun 04 '17 at 19:29
  • 1
    Possible duplicate of [Safely turning a JSON string into an object](https://stackoverflow.com/questions/45015/safely-turning-a-json-string-into-an-object) – Jeen Broekstra Jun 05 '17 at 00:42

1 Answers1

1

You are already storing the results as a list in $scope.results.

To use the values for s in a dropdown menu, for example, you can do this:

<select ng-options="item as item.s.value for item in results" ng-model="selected"></select>

Plunkr

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
evsheino
  • 2,147
  • 18
  • 20