为什么我无法在控制器中获得参数?

时间:2015-07-27 08:49:57

标签: javascript angularjs

请帮我这个,我想用分页显示数据,但在Controller方法中,我无法获得参数。

我创建了一个codepen,请在http://codepen.io/SmilePark/pen/vOVPXy

上查看

这是我的观点:

<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();
}

当我点击“最后一页”时,$scope.currentPage是&#39; NaN&#39;,这有什么问题?

1 个答案:

答案 0 :(得分:2)

(我无法评论因此写在这里)..是你的http请求返回data.numTotal作为值?否则我的代码没有任何问题。

相关问题