What is preventing me from retrieving the parameter in the controller?

I could use some assistance with implementing pagination for displaying data. However, I am encountering issues in retrieving the parameter in the Controller Method.

To provide more context, I have created a demo on CodePen which can be viewed at http://codepen.io/SmilePark/pen/vOVPXy

Below is a snippet of my view:

<div class="col-md-12">
    <nav>
        <ul class="pagination">
            <li ng-class="{true:'active'}[currentPage==1]"><a href="javascript:void(0)" ng-click="currentPage=1;load()">Home Page</a></li>
            <li ng-class="{true:'disabled'}[currentPage==1]"><a href="javascript:void(0);" ng-click="prev()">Prev</a></li>
            <li ng-repeat="page in pages"><a href="javascript:void(0);" ng-click="currentPage=page;load()">{{ page }}</a></li>
            <li ng-class="{true:'disabled'}[currentPage==totalPage]"><a href="javascript:void(0);" ng-click="next()">Next</a>
            </li>
            <li ng-class="{true:'active'}[currentPage==totalPage]"><a href="javascript:void(0)" ng-click="currentPage=totalPage;load()">Last Page</a></li>
        </ul>
    </nav>
</div>

Additionally, here is an excerpt from my controller:

userApp.controller('userCtrl', ['$scope', '$http', 'serverUrl', function($scope, $http, serverUrl) {
$scope.currentPage = 1;
$scope.currentCount = 3;
$scope.pages = [];

$http.get(serverUrl + "/users?page=" + $scope.currentPage + "&count=" + $scope.currentCount + "&mobile=&userId=0&status=1").success(function(data) {
    if (data.code == 0) {
        $scope.items = data.data.users;
        $scope.totalPage = Math.ceil(data.numTotal / $scope.currentCount);
        for(var i=1;i<$scope.totalPage+1;i++){
            $scope.pages.push(i);
        }
    }
})

$scope.searchData = function() {
    $scope.load();
}
$scope.load = function() {
    var userId = 0,
        mobile = "",
        startDate = "",
        endDate = "";
    if ($scope.userId != undefined) {
        userId = $scope.userId;
    }
    if ($scope.mobile != undefined) {
        mobile = $scope.mobile;
    }
    if ($scope.startDate != undefined) {
        startDate = new Date($scope.startDate).getTime();
    }
    if ($scope.endDate != undefined) {
        endDate = new Date($scope.endDate).getTime();
    }
    var url = serverUrl + "/users?page=" + $scope.currentPage + "&count=" + $scope.currentCount + "&mobile=" + mobile + "&userId=" + userId + "&startDate=" + startDate + "&endDate=" + endDate + "&status=1";
    $http.get(url).success(function(data) {
        if (data.code == 0) {
            $scope.items = data.data.users;
        }
    })
}
$scope.loadLast = function(){
    $scope.currentPage = $scope.totalPage;
}

$scope.prev = function() {
    $scope.currentPage--;
    $scope.load();
}

$scope.next = function() {
    $scope.currentPage++;
    $scope.load();
}

Upon clicking the 'Last Page' button, I encounter an issue where $scope.currentPage becomes 'NaN'. Can anyone help troubleshoot this problem?

Answer №1

I was unable to leave a comment, so I'll post here instead. Have you confirmed that your HTTP request is returning data.numTotal as expected? If not, everything in your code looks fine to me.

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

Retrieving data from an external PHP script

I'm facing an issue with retrieving results from a PHP file after submitting a form: index.php (located at ) <form id='loginForm' action='http://domain1.com/mail.php' method='POST'> <input id=&apo ...

Is it possible to combine Ajax, JS, HTML, PHP, and MySQL in a single project?

I am looking to create a web application and wondering if I can integrate Ajax, JavaScript, HTML, PHP, and MySQL all together? ...

Leveraging AngularJS $location to Manipulate Headers

I am attempting to establish a connection with another website on my server. Currently, I am utilizing $location.url('http://127.0.0.1/second'); to redirect to the second site, but I require setting the Authorization Header to a custom variable. ...

When attempting to reference a custom module within a React application, the error message "moment is not a function" may appear

I am facing an issue while trying to integrate a custom module I developed into a basic React application using react-boilerplate. Upon importing the module, I encountered an error stating that the moment function within the module is undefined. Here is t ...

Establish the following 13 steps to configure the initial server state and retrieve the client state

Currently, I have 13 applications and I am utilizing Zustand as my state manager. Below is a simple layout example: <MainProvider> <div className="min-h-screen flex flex-col"> <Navbar></Navbar> <main className ...

Retrieve the current URL of an IFRAME

How can I easily retrieve the current URL from an embedded iframe? The user will be navigating through various web pages. I assume that some JavaScript code would be needed for this task. ...

Can the server determine if a Parse user is currently logged in?

My current system allows users to log in or sign up client side, but I want to verify their login status from the server when they land on a page through a GET request. Is it feasible to do this? ...

Angular 2's Implementation of Hierarchical Dependency Injection

I'm encountering a problem with my Angular 2 application. I have a root component, AppComponent, where I've injected a service called ProductService. Now, I am trying to resolve this service in one of the child components, ProductList, but I keep ...

How can I add an object to an array of objects in Vue.js?

Hey there! I'm new to Vue and currently working on understanding the whole concept of Vue and how to use it. Right now, my focus is on learning lists. JS: Vue.config.productionTip = false; new Vue({ el: '#app', data: { items: [ ...

Display a specific division depending on the outcome of an Ajax request within a PHP form

My PHP form has a layout similar to this: <form> <div id="inid"> National ID: <input type="text" id="individual_nid" oninput="getIndividualName(this.value)" /> </div> <hr /> name: <div id="individua ...

What could be causing me to receive no results?

Currently, I am expanding my knowledge in JavaScript, Ajax, and NodeJs. My current project involves creating a webpage that can display a string retrieved from the server. The server-side code is as follows: var express = require('express'); v ...

Send a Javascript variable to a Python controller using AJAX

Programming is still new to me and I find myself in unfamiliar territory... I am working on creating an app that relies on button clicks to gather information and provide data analysis based on those interactions. While this functionality works using pure ...

Steps for creating a TypeScript class that can implement an interface

As a beginner in TypeScript, I am looking for help with the following code snippet: async function sleep(ms: number) { return new Promise((resolve, reject) => { setTimeout(() => resolve(), ms) }) } async function randomDelay() { ...

Is there a method to prevent the repetition of this loop?

I have a question regarding my React app development. I am currently using useEffect to loop through six items every time, even when only one item has changed. How can I optimize this so that only the variable that was changed in the reducer function is ...

Exploring the features of Vue.js with the code snippet 'ts 1109'

I need some assistance with my code as I seem to have one incorrect answer when using the if statement. The error code that I am encountering is ts1109 and I am not sure why VS Code is showing this. Thank you in advance for any help provided :) var calcu ...

Opting for Mysql over MongoDB as the provider in Next.js with Next-auth

Exploring the Next.js framework for the first time, I've dived into using Next-auth to handle sign-up/login functionality based on the provided documentation. My experience so far has been smooth, especially with the MongoDB provider as recommended i ...

Relocating to the middle of the webpage (Automatically resize for mobile compatibility if feasible)

Apologies for my poor English. Are there any suggestions on how to center this without using margins or other methods? Perhaps there are alternative solutions. https://i.sstatic.net/dXfwL.png Also, is it feasible for the image and video to automatically a ...

Compatibility issues with jQuery observed in Firefox and Internet Explorer 11

Check out the code here: jsfiddle demo HTML CODE: <div class="first"> <!-- Part one --> <div class="acord_col"> <div class="img_class" id="exist_site"></div> <div class="intro_text"> </div> </div&g ...

The Ionic application is experiencing difficulties in loading the JSON file

I am currently delving into the world of Ionic development and utilizing localhost to test my app. My goal is to create a contacts list application where contact details such as name, email, phone number, and avatar are loaded from a JSON file. However, I& ...

Collaborating with multiple forms and files in PHP using jQuery and AJAX operations

Need help with the title for this question. There are two input fields and buttons in index.php <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST"> <input type="text" class="for ...