Is a separate controller necessary for Pagination in web apps?

Hey there, I'm relatively new to Angular and having some trouble with pagination. No matter what I try, I can't seem to link my directive to the content properly. Should I include the pagination info in the same controller that's used for the rest of the page? My goal is to display only five objects per page. I initially copied JS code and tried converting it to TypeScript, which might be causing issues.

Let me show you my controller:

export class HomeController {
    public challenges;
    public challengesCompleted;
    //public allCompletedChallenges;
    public totalItems = 1;
    public currentPage = 1;
    public maxSize = 1;
    public bigTotalItems = 1;
    public bigCurrentPage = 1;
    public setPage(pageNo) {
        this.currentPage = pageNo;
    };



    constructor
        (
        private challengeService: MyApp.Services.ChallengeService,
        private $location: angular.ILocationService,
        $routeParams: ng.route.IRouteParamsService
        ) {
        this.challenges = this.challengeService.listChallenges();
        this.challengesCompleted = this.challengeService.list10FinishedChallenges();
        this.maxSize = 5;
        this.bigTotalItems = 5;
        this.bigCurrentPage = 5;

        //this.allCompletedChallenges = this.challengeService.listAllCompletedChallenges();
    }


}

and here's the HTML snippet:

                <div class="row" ng-repeat="challenge in controller.challenges  | filter: globalSearch">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-6">
                                <h4>
                                    Created By: {{challenge.challenger}}
                                </h4>
                            </div>
                            <div class="col-md-6">
                                <h4>{{challenge.dateCreated  | date: 'longDate'}}</h4>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <h4>Title: <b>{{challenge.title}}</b></h4>
                            </div>
                            <div class="col-md-6">
                                <h4>Bet Amount: {{challenge.amount}}</h4>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <h4>
                                    Description
                                </h4>
                                {{challenge.description}}
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <a ng-hide="challenge.challengee!=null || !account.isLoggedIn() || account.getDisplayName() == challenge.challenger" href="/acceptChallenge/{{challenge.id}}"><b>ACCEPT THIS CHALLENGE!</b></a>
                                <a ng-show="!account.isLoggedIn() && challenge.challengee == null" href="/login"><b>YOU MUST BE LOGGED IN TO ACCEPT THIS CHALLENGE.</b></a>
                                <p ng-show="challenge.challengee!=null"><b><i>Challenge has been accepted by {{challenge.challengee}} and is in progress.</i></b></p>
                            </div>
                            <div class="col-md-12 linebreak">

            <br />
        </div>
                    </div>
                </div><br /><br />
            </div>
                            <uib-pagination total-items="totalItems" ng-model="controller.currentPage" items-per-page=5 max-size="5" class="pagination-sm" boundary-link-numbers="true">
                            </uib-pagination>

        </div>
    </div>
</div>

Your assistance would be greatly appreciated. Thanks a bunch!

Answer №1

It appears that you are not utilizing the ng-change attribute in the uib-pagination. To remedy this, you should connect it to the method responsible for handling actual paging.

An example implementation could look like this:

$scope.pageChanged = function(){
    $scope.pagedChallenges = $scope.challenges.slice....
}

Additionally, ensure that pagedChallenges is bound to the view.

A more efficient approach would involve implementing paging on the server side. When the page changes, a request can be sent to the server to retrieve the necessary data.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Display the child elements of an object retrieved from Firebase within an AngularJS application

Incorporating the "denormalized" data approach discussed by @Anant on the Firebase blog. To efficiently handle child objects, he recommends listening for child_added events on the parent to retrieve the child ids, then individually querying those children ...

Implementing $http in AngularJS

I am encountering the following issue: angular.module('myApp').factory('dashboard', ['$http', function ($http) { return { name: function(str){ return str + ':' + 'works!'; ...

The issue of the view in AngularJS not being updated when attempting to use jQuery AJAX

Below is my AngularJS controller: function MemberCtrl($scope){ $.ajax({ url: "/getmembers", type: "get", success:function(data){ $scope.members = data.member_list; console.log($scope.members); //works fi ...

Develop a custom directive that incorporates ng-model and features its own distinct scope

UPDATE - I have generated a Plunker I am in the process of developing a personalized directive to be utilized for all input fields. Each input will have distinct options based on the logged-in user's requirements (mandatory, concealed, etc), so I bel ...

Troubleshooting: Issues with the functionality of ng-include in AngularJS

Hi there, I am new to angular js and I'm attempting to integrate a simple html file into my page. Below is the code I am using: <!DOCTYPE html> <html ng-app=""> <head> </head> <body ng-controller="userController"> < ...

A Multilingual Application developed using either AngularJS or the Ionic Framework

Having recently delved into both AngularJS and the Ionic Framework, my background is primarily in Microsoft technologies. I am currently working on developing an app that supports three languages: English, Arabic, and French. Drawing from my experience wi ...

The issue arises when an AngularJS directive fails to recognize the controller's scope due to binding variables using "this"

In my setup, I have an angularJS controller as well as a directive that work together: angular.module('twitterApp', []) .controller('AppCtrl', AppCtrl) .directive('enter', EnterFunc); function AppCtrl($scope) { $ ...

Accessing instance variables from a chained observable function in Angular 2/Typescript

Currently, I am utilizing Angular2 along with Typescript. Let's assume that there is a dummy login component and an authentication service responsible for token authentication. In one of the map functions, I intend to set the variable authenticated as ...

"Unlock the power of Angular.js: Extracting table row data with the click of a checkbox

Can anyone help me with this? I am trying to retrieve all checked data from a table row using Angular.js. Below is my code: <tr ng-repeat="gl in galleryDatas"> <td><input type="checkbox" name=""> {{$index+1}}</td> <td><img ...

Does the Cors problem happen exclusively during a "put" request?

I am currently developing an Angular application that utilizes ng-resource. The backend service API is created using Asp.Net Core web api and CORS has been enabled. Here is the code snippet for service.js: .factory('D2Service', ['$resource ...

tips for selecting a specific number of records using an ajax call

My database contains 10,000 records. Using AJAX, I am able to fetch all 10,000 records in JSON format. However, I want to modify the behavior so that it only fetches the first 100 records initially, and then fetches another 100 records on subsequent reques ...

Gradually reveal image as the page loads

Is there a way to smoothly fade in an image when the page loads using Angular JS? I've tried implementing the following code with AngularJS, but it doesn't seem to be working correctly (source: http://plnkr.co/edit/ncqEB3PafIWbwv0UH1QG?p=preview) ...

How to properly link Django static files in external JavaScript

My Django application integrates AngularJS with various JavaScript and template files. Within my Django template, I can utilize the {% static %} tag to correctly refer to these files, like so: <script src="{% static "angular/myapp.app.js" %}"></ ...

Verify characteristics of recursive object within Angular 7

I have an object similar to the one in the stackblitz linked below and I need to determine if a key is of type Date. If it is, I want to add 3 days to that date. I have successfully implemented this for non-recursive objects, but I am facing challenges wit ...

What is the best way to incorporate a @types module into a TypeScript file that is not already a module?

Setting the Stage: In the process of shifting a hefty ~3,000 line inline <script> from a web-page to a TypeScript file (PageScripts.ts) to be utilized by the page through <script src="PageScripts.js" defer></script>. This script entails ...

Outputting a JS file per component using Rollup and Typescript

Currently, I am in the process of developing a component library using React, TypeScript, and Rollup. Although bundling all components into a single output file index.js is functioning smoothly, I am facing an issue where individual components do not have ...

Seeking guidance for the Angular Alert Service

I'm relatively new to using Angular and I'm struggling to determine the correct placement for my AlertService and module imports. Currently, I have it imported in my core module, which is then imported in my app module. The AlertService functions ...

Leveraging async/await in conjunction with callback functions

I am in the process of creating a service layer on top of mongoDB. I have a User object that contains an array of referenced Achievements. Once the user is authenticated using JWT or another method, I go into the service layer and retrieve the relationshi ...

MQTT Broker specialized in Typescript

I'm looking to create a MQTT Broker using TypeScript and Angular. I've attempted a few examples, but I keep encountering the following error: Uncaught TypeError: http.createServer is not a function Here's a simple example of what I'm c ...

The sequence for initializing properties in Typescript

In my Typescript code, I have 2 classes named A and B. Class B inherits from class A, where class A's constructor calls a function called init, and class B overrides the init function. a.ts export default class A { constructor() { this.ini ...