0

I am trying to consume a Django REST pagination object using Angular 11. I not a total coding noob, but I am very new to Angular.

Currently my Django REST api is configured to paginate every 6 items, and the total items in the object is 10. Django then outputs a "next" URL that would work fantastic with Django's string interpolation feature, but is not so easily figured with Angular.

I followed this tutorial closely, not just because it has nearly complete codeblocks, but also because it's legit the only complete code example dealing with Django REST API and Angular pagination that I could find on Google: Link to other stackoverflow question dealing with this same issue, but remains unreasolved

The Django API outputs this object: Django REST API Paginated output

My Angular model is thus: Angular model

My pagination service: My pagination service

My component: Component I'm trying to paginate

My rendered result: The browser's rendered result

And the console error message: ERROR TypeError: Cannot read property 'results' of undefined

Any help would be much appreciated!

1 Answer 1

0

Your API response is

{
   results: []
}

The way you use the response is response.data.results. Property data doesn't exist in response.

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

1 Comment

This is the correct answer. Replaced "res.data.results" with "res.results" and it began working. Thanks!

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.