How to get Odata Next Link from returned JSON object using angular $ http service

I have applied Odata request syntax for my web api. I can successfully return only the first 10 results and a link for further results. However, I cannot retrieve this link from the JSON object that is returned by the server using my angular interface.

Let's assume the server responds like this:

{
  "odata.metadata":"http://localhost:60497/odata/$metadata#tables","value":[
    {
      "id":001,"name":"abc"
    },{
      "id":002,"name":"pqr"
    },{
      "id":003,"name":"xyz"
    },{
      .
      .
      .
  ],"odata.nextLink":"http://localhost:60497/odata/tables?$skip=10"
}

      

Now I am showing the data using the $ http success method by assigning the returned data to a variable and using ng-repeat. I assign it like this:

.success(function(data)){
  $scope.foo = data.value;
}

      

However, when I try to access the following link using:

$scope.link = data.odata.nextLink;

      

in the success method it gives me an error. What am I missing here? How else can I access the returned link? Is there any other way for server side deployment?

+3


source to share


4 answers


I had the same problem, more or less. I am guessing it has to do with JavaScript objects and their properties. Link

data.odata.nextLink

      

means that there is a property "odata" with a sub-property / field "nextLink". It is not, "odata.nextLink" is the name of the property. I don't know why OData looks like this.



I got the content of this property using a string reference ie

data['odata.nextLink']

      

Don't know if there is any drawback, but it seems to work ...

+6


source


    using Newtonsoft.Json;     
    [JsonProperty("@odata.nextLink")]
    public string nextPage { get; set; }

      



+2


source


I got it to work with

theReturnedObject['@odata.nextLink']

      

+1


source


Remember odata values ​​must have @ in front of them. I'm not sure how your implementation handles this character, but it must be a valid prefix.

The problem I'm having is that some providers use the full path and some only use the relative path from the service endpoint.

0


source







All Articles