javascript - AngularJS 10 $digest() 迭代达到列表显示时

标签 javascript angularjs

我的js代码是:

// 在变更分布的时候,重新获取数据条目
$scope.reGetProducts = function(){
        // 发送给后台的请求数据
        $scope.model.cpage=$scope.paginationConf.currentPage;
        $scope.model.len=$scope.paginationConf.itemsPerPage;

        $http({
            method  : 'POST',
            url     : '<%=request.getContextPath()%>/sysConfigManage/querySysConfigList.action',
            data    : $scope.model,  // pass in data as strings
            headers : { 'Content-Type': 'application/x-www-form-urlencoded' }  // set the headers so angular passing info as form data (not request payload)
        }).success(function(data){
            // 变更分页的总数
            $scope.paginationConf.totalItems = data.total;
            // 变更列表条目
            $scope.items = data.rows;
        });
    };

    // 配置分页基本参数
    $scope.paginationConf = {
        currentPage: 0,
        itemsPerPage: 10
    };
    $scope.model = {};
    $scope.items = {};
    // 通过$watch currentPage和itemperPage 当他们一变化的时候,重新获取数据条目
    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',$scope.reGetProducts);

html 是

<tr bindonce ng-repeat="item in items">
    <td>
        <button type="button" class="btn btn-success" ng-click="getDetaile(item.ID)">详情</button>
        <button type="button" class="btn btn-danger"  ng-click="del(item.ID)">删除</button>
    </td>
    <td bo-text="item.NAME"></td>
    <td bo-text="item.CODE"></td>
    <td bo-text="item.VALUE"></td>
    <td bo-text="item.MEMO"></td>
</tr>

为什么会出现这个错误,请帮助我,,,..

最佳答案

问题出在这里:

 $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',$scope.reGetProducts);

您正在观看一场永远不稳定的行动。在每个摘要调用中,Angular 都会比较计算结果并比较两个新对象。

在此处了解更多信息:https://docs.angularjs.org/error/ $rootScope/infdig

因此 Angular 无法确定稳定的模型。您可以轻松地编写:

$scope.$watchGroup(['paginationConf.currentPage', 'paginationConf.itemsPerPage'], $scope.reGetProducts);

关于javascript - AngularJS 10 $digest() 迭代达到列表显示时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27888457/

相关文章:

javascript - AngularJs 在传递到我的 Controller 之前删除响应 header

asp.net - 使用 jQuery 获取图像尺寸时遇到问题

javascript - 在改变 Angular 数组时设置 <tr> 颜色

javascript - 使用基于值的 jQuery 代码更改 SharePoint 列表字段颜色?

javascript - 测试特殊和 html 代码

AngularJS - 如何在输入时在文本框上应用货币过滤器?

javascript - 在 ng-repeat 中显示/隐藏 onclick 按钮

javascript - 如何在ng-repeat下拉输入框中添加占位符?

javascript - 如果所有模型值不为空则显示 Angular

javascript - Bootstrap 文本字段不会 100%