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

Having trouble retrieving the data property from the parent component within the child component slot

I am facing an issue with my Vue components. I have a rad-list component and a rad-card component. In the rad-list component, I have placed a slot element where I intend to place instances of rad-card. The rad-card component needs to receive objects from t ...

Encountering an issue of duplicate key error when using multiple v-for loops with various keys

I've encountered an issue while working on a Python application that utilizes Vue.js. A ticket came my way with an error message stating: [Vue warn]: Duplicate keys detected: ''. This may cause an update error. (found in Root) The pro ...

Is there a way to adjust user privileges within a MenuItem?

One of my tasks is to set a default value based on the previous selection in the Userlevel dropdown. The value will be determined by the Username selected, and I need to dynamically update the default value label accordingly. For example, if "dev_sams" is ...

Refresh the HTML webpage using AJAX technology

I am trying to implement a simple html page with a single table that updates in the background every 5 seconds. The traditional solution of using <meta http-equiv="refresh" content="5"> is not suitable as it would disrupt the user experience by displ ...

With the power of jQuery, easily target and retrieve all label elements within a specified

Currently, I'm working on developing a function that should be executed whenever any of the labels for a particular group of radio buttons are clicked. So, I need a way to reference all the labels in this radio button group. In my search for a soluti ...

Exploring the power of Blowfish encryption with Java and JavaScript

I am facing an issue where I need to encrypt data using Blowfish on a java-based server and send it to a client. Despite successfully encrypting the data, I am unable to decrypt it on the client side. Below is my Java code snippet: byte[] kd = key.getByt ...

Error message: "Window object not defined during NextJS build process."

Why am I encountering a 'window not defined' error? I haven't referenced window or document in my code, and it runs without issues during development but throws an error during the build process. ReferenceError: window is not defined at ...

Is it possible to display different alert messages based on the language chosen?

Recently, I implemented a newsletter pop-up feature that allows users to sign up for a weekly newsletter. When a user tries to submit without entering their email address, an alert message pops up prompting them to do so. This is beneficial but now I wan ...

Uncovering hidden links in a menu with Python Selenium and JavaScript

Can someone provide guidance on how to activate the JavaScript submenu associated with this button, "x-auto-54"? <table id="x-auto-54" class=" x-btn avtar-x-btn x-component x-btn-noicon x-unselectable " cellspacing="0" role="prese ...

Having issues with the Grunt build on Yo Angular

I created an Angular App using the Yo angular-generator tool. Initially, I had no issues building the app with Grunt Build. However, I decided to integrate Bootstrap 3 and also ran npm install grunt-bower-install. To incorporate these changes, I made mod ...

Get detailed coverage reports using Istanbul JS, Vue JS, Vue CLI, Cypress end-to-end tests, and Typescript, focusing on specific files for analysis

I have a VueJS app written in Typescript that I am testing with Cypress e2e tests. I wanted to set up coverage reports using Istanbul JS to track how much of my code is covered by the tests. The integration process seemed straightforward based on the docum ...

Flask is failing to display AJAX data

Looking to embark on a Flask project involving sending an AJAX request. In the Flask code, I want to assign a variable to handle the request and display it on the page using a Jinja variable. Flask from flask import Flask,render_template,request app = Fla ...

Unable to render Angular charts

Recently, I've been attempting to integrate angular charts using the chart.js bundle sourced from CDN links. The version of Angular being used is 1.5.7 and for chart.js it's 2.1.6. I encountered the following error message: angular.js:13708 T ...

What is a more efficient method for incorporating optional values into an object?

Currently, I am utilizing the optional addition feature in this way: ...(!!providerId && { providerId }), ...(!!practiceId && { practiceId }), Is there a more elegant shorthand method to replace this logic, such as: yield createRemark ...

Something is seriously wrong with the datetime in fullcalendar JavaScript

I've been diving into a tutorial for creating a calendar scheduler in asp.net MVC5 from this link. One issue I'm facing is the datetime being passed and stored as the min value in the database (1/1/0001 12:00:00 AM), almost like it's null b ...

What is the reasoning behind placing CDN links at the bottom of the index file?

What is the reason for placing CDN links for AngularJS file at the end of the index page? I initially placed it at the top of the file and it worked fine. Is there a significant difference between these two placements? ...

A proposal for implementing constructor parameter properties in ECMAScript

TypeScript provides a convenient syntax for constructor parameter properties, allowing you to write code like this: constructor(a, public b, private _c) {} This is essentially shorthand for the following code: constructor(a, b, _c) { this.b = b; thi ...

Can one manipulate SVG programmatically?

Looking to develop a unique conveyor belt animation that shifts items on the conveyer as you scroll down, then reverses when scrolling up. I discovered an example that's close to what I need, but instead of moving automatically, it should be triggered ...

The troubleshooting of a find method in Mongoose

Why is it necessary to use await twice when calling the model function, even though we already used await in the model itself: async function model() { return await data.find({}, '-_id -__v') } When I console.log await data.find({}, '-_id ...

Guide on utilizing the list of names in a POST request

<td class="widht200"> <input type="text" name="agg" size="2" disabled="disabled"/> </td><td class="widht200"> <input type="text" name="agg" size="2" disabled="disabled"/></td><td class="widht200"> <input type=" ...