Javascript 为什么我能';无法在控制器中获取参数?

Javascript 为什么我能';无法在控制器中获取参数?,javascript,angularjs,Javascript,Angularjs,请帮助我,我想用分页显示数据,但在控制器方法中,我无法获取参数 我创建了一个代码笔,请在屏幕上查看 我的看法是: <div class="col-md-12"> <nav> <ul class="pagination"> <li ng-class="{true:'active'}[currentPage==1]"><a href="javascript:void(0)" ng-click="cu

请帮助我,我想用分页显示数据,但在控制器方法中,我无法获取参数

我创建了一个代码笔,请在屏幕上查看

我的看法是:

<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>

这是我的控制器:

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();
}
userApp.controller('userCtrl',['$scope','$http','serverUrl',函数($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”)。成功(函数(数据){
如果(data.code==0){
$scope.items=data.data.users;
$scope.totalPage=Math.ceil(data.numTotal/$scope.currentCount);

对于(var i=1;i(我无法发表评论,因此在此写作)…您的http请求是否将data.numTotal作为值返回?否则,我看不出您的代码有任何问题。

当最后一页将当前页定义为1时。@BhojendraNepal抱歉,我不太明白您的意思。是的numTotal是8,当我单击“最后一页”时,http请求是:“”,访问用户时“页面”是“NaN”-您正在使用data、 对于numTotal,您可以直接使用它data.numTotal…除了data.numTotal,我看不出任何其他问题,也许如果您可以创建一个带有示例http响应的代码笔…我可以尝试为您解决这个问题。正如我所预测的,它应该是data.data.numTotal,因为numTotal在函数参数数据的数据属性中,因此以下是更改-$scope.totalPage=Math.ceil(data.data.numTotal/$scope.currentCount);