限制Angular中的数据集

时间:2016-08-31 16:47:06

标签: angularjs

我正在尝试仅在加载时显示前5个记录。这是生成数据集的角度服务。我怎样才能做到这一点?

 myApp.service('allCurrentSettingsService', ['$http', '$q', function ($http, $q) {
        var allSettings = null;
        this.getList = function () {
            var def = $q.defer()
            if (allSettings) {
                def.resolve(allSettings);
            } else {
                $http.post('GetAllCurrentSettings')
                  .then(function (response) {
                      var response = $.parseJSON(response.data)
                      allSettings = response;
                      def.resolve(allSettings);
                  });
            }
            return def.promise;
        }
    }]);

2 个答案:

答案 0 :(得分:1)

You have to add $scope.Records = 5;

In you html file while getting records in ng-repeat add limitTo:Records it will simply give you last five records.

答案 1 :(得分:1)

You have to use a scope variable

$scope.limit = 5;

Then, use LimitTo filter in HTML file for initial loading like

ng-repeat="data in query | limitTo:limit"

After that, if you want to load more records on the click of some button or scroll till last of the page, you can write the below code on appropriate event

$scope.increseLimit = function()
{
  $scope.limit+=5;
}