0

I get data from the database using the $http service and get() method. The database contains 100 records in the form of an array of objects, but I only need to get the first 10 records, not all 100.

How do I correctly write a query to retrieve only 10 records?

4
  • 1
    depends on server side, you just make request at front end Commented Dec 13, 2017 at 19:58
  • You may want to include some code, just to show others what you're doing now. Commented Dec 13, 2017 at 20:00
  • What is your backend? Does it support a page request? Something like /data?size=10? Commented Dec 13, 2017 at 20:04
  • AngularJS is client side. Your backend should provide a query where you can specify how many elements desire to get Commented Dec 13, 2017 at 20:17

1 Answer 1

0

You can take only first 10 records in Angular at the Client side, just add below code.

Suppose you're getting 6 records, wanted to display only 3 then,

var app = angular.module('myApp', []);
app.controller('sizeCtrl', function($scope) {
    $scope.cars = ["Audi", "BMW", "Dodge", "Fiat", "Ford", "Volvo"];
});

in Html

<div ng-app="myApp" ng-controller="sizeCtrl">
<ul>
<li ng-repeat="x in cars | limitTo : 3">{{x}}</li>
</ul>
</div>
Sign up to request clarification or add additional context in comments.

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.