Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs ui bootsrap分页:加载页面时未禁用“第一页”按钮_Angularjs_Angular Ui Bootstrap - Fatal编程技术网

Angularjs ui bootsrap分页:加载页面时未禁用“第一页”按钮

Angularjs ui bootsrap分页:加载页面时未禁用“第一页”按钮,angularjs,angular-ui-bootstrap,Angularjs,Angular Ui Bootstrap,我正在显示ng include中的元素列表。 元素列表来自使用$resource query服务的服务器。 该列表使用该指令进行分页。服务器在Json头中发送分页信息(属性名为X-MyApp-…),并被query回调函数截获 以下是html: <table ng-include src="'partials/tplList.html'" ng-init="listInit = {'type': collec.type, 'offset': 1}" ng-controller="ListCt

我正在显示ng include中的元素列表。 元素列表来自使用
$resource query
服务的服务器。
该列表使用该指令进行分页。服务器在Json头中发送分页信息(属性名为X-MyApp-…),并被
query
回调函数截获

以下是html:

<table ng-include src="'partials/tplList.html'" ng-init="listInit = {'type': collec.type, 'offset': 1}" ng-controller="ListCtrl" >
</table>
以及服务:

factory('List', function($resource){
    return $resource('url/to/the/json/:type', {type:'@type'});
})
除了一件事之外,一切都正常工作:当页面加载时,分页组件中的第一个页面按钮(“1”)没有像应该的那样被禁用(“上一个”和“第一个”按钮也没有禁用)。直到我单击另一个页码(选中时已正确禁用),然后单击第一页按钮上的“上一步”,它才被禁用


有什么想法吗

我找到了一个让它工作的方法:

已从控制器中删除此行:

 $scope.currentPage = response("X-MyApp-currentPage");
并增加了这个,

$scope.currentPage = 1;
其中:

controller('ListCtrl', ['$scope', 'List', function($scope, List) {
// collect: concatenate the objects before to send it to loadList()
$scope.collect = function (a,b){
    var c = {};
    for (var att in a) { c[att] = a[att]; }
    for (var att in b) { c[att] = b[att]; }
    return c;
}

$scope.currentPage = 1;

$scope.loadList = function (param) {
    $scope.list = List.query(p, function(list, response) {
        $scope.pageCount = response("X-MyApp-pagesCount");
    }); 
}
}])

显然,分页组件不需要服务器提供的
X-MyApp-currentPage
信息(我不知道为什么)

我找到了一个让它工作的方法:

已从控制器中删除此行:

 $scope.currentPage = response("X-MyApp-currentPage");
并增加了这个,

$scope.currentPage = 1;
其中:

controller('ListCtrl', ['$scope', 'List', function($scope, List) {
// collect: concatenate the objects before to send it to loadList()
$scope.collect = function (a,b){
    var c = {};
    for (var att in a) { c[att] = a[att]; }
    for (var att in b) { c[att] = b[att]; }
    return c;
}

$scope.currentPage = 1;

$scope.loadList = function (param) {
    $scope.list = List.query(p, function(list, response) {
        $scope.pageCount = response("X-MyApp-pagesCount");
    }); 
}
}])

显然,分页组件不需要服务器提供的
X-MyApp-currentPage
信息(我不知道为什么)

之所以发生这种情况,是因为ng include创建了一个新的作用域,并且模型没有在$parent作用域中修改

请尝试以下代码或创建一个与父控制器通信的控制器

<pagination num-pages="pageCount" current-page="$parent.currentPage" max-size="10" on-select-page="loadList(collect(listInit, {offset: page}))">
    </pagination>

之所以发生这种情况,是因为ng include创建了一个新的作用域,并且模型没有在$parent作用域中修改

请尝试以下代码或创建一个与父控制器通信的控制器

<pagination num-pages="pageCount" current-page="$parent.currentPage" max-size="10" on-select-page="loadList(collect(listInit, {offset: page}))">
    </pagination>