为什么我的tr ng-repeat在点击分页链接时会消失

时间:2015-07-07 22:36:59

标签: angularjs pagination angularjs-ng-repeat angular-ui-bootstrap angular-resource

使用angular-bootstrap服务器端分页和$ resource / $ http。我正在运行搜索并返回多个记录。然后我在tr元素上使用ng-repeat来填充表格。这一切都很好。当我点击任何分页按钮时出现问题。在发生任何事情之前(即资源调用或dom操作)我将使用ng-repeat on从DOM中删除。任何想法为什么以及如何在将来避免这种情况?

我的html,TR元素:

<tr class="animate-repeat" ng-repeat="agent in agentDataModel">

分页HTML

<div class="text-center">
        <pagination                 
            data-ng-model="agentDataModel"
            data-page="agentDataModel.currentPage"
            data-total-items="agentDataModel.totalItems"
            data-items-per-page="25"
            data-max-size="5" 
            data-ng-change="setPage(2)"
            >                    
        </pagination>
    </div>

我的控制器 - 提交搜索功能

$scope.submitSearch = function(newSearchVal, pageNo) {
        $rootScope.moduleLoading = true;

        agentService.get(newSearchVal)
            .$promise.then(
            function success(r) {
                $rootScope.moduleLoading = false;

                if(typeof r.total_items !== 'undefined') { 
                    if(r.total_items > 0 ) {
                        // May be one or multiple results (variable results)

                        // fetch agents and map the data to $scope var
                        $scope.$parent.agentDataModel               = r._embedded.agents;
                        // set pagination options
                        $scope.$parent.agentDataModel.itemsPerPage  = r.page_size;
                        $scope.$parent.agentDataModel.page_count    = r.page_count;
                        $scope.$parent.agentDataModel.totalItems    = r.total_items;
                        $scope.$parent.agentDataModel.currentPage   = 1;                            
                        $scope.$parent.agentDataModel.links         = r._links;
                        $scope.$parent.agentDataModel.next          = r._links.next.href;
                        $scope.$parent.agentDataModel.page          = r.page;

                        // set flags
                        $scope.$parent.singleResult                 = false;
                        $scope.$parent.showResult                   = true;

                        // debug
                        if($rootScope.env === 'dev') {dev.log('Page changed to: ' + $scope.$parent.currentPage);}
                    } else {
                        // HMMM no results? Set flags
                        $scope.$parent.singleResult = false;
                        $scope.$parent.showResult   = false;
                        $scope.$parent.alert.info   = true;
                        showInfoAlert('We found 0 agents with that search.','n');                        
                    }
                } else {
                   // Absolutly one result ready for the form view
                   // set flags
                    $scope.$parent.showResult       = true;
                    $scope.$parent.singleResult     = true;
                    $scope.$parent.isHidden         = false;
                    // set single agent data
                    $scope.$parent.agentDataModel   = r;
                }                   
            }, 
            function error(msg) {
                $rootScope.moduleLoading = false;
                dev.log('error');
                dev.log(msg);
                var myError             = msg;
                var theQuery            = myError.config.params.query;
                var myErrorURL          = myError.config.url;
                var myErrorType         = myError.data.type;
                var myErrorTitle        = myError.data.title;
                var myErrorStatus       = myError.status;
                var myErrorStatusText   = myError.statusText;
                var myErrorDetail       = myError.statusText;
                var myErrorMsg          = "FATAL ERROR - The search with query ?query="+ theQuery +"! The URL: " + myErrorURL + 
                            " responded with a status of " + myErrorStatus +": "+ myErrorStatusText + 
                            ". DETAILS: " + myErrorDetail+". "+ 
                            "Please click this link to send an error report <a href='mailto:xxxxx@xxxxxx.com?subject=Search Error&body="+myErrorURL+"'>" + myErrorURL + 
                            "</a>.";
                showErrorAlert(myErrorMsg);                    
            }
        );  
    };

当然,我们将非常感谢任何帮助

0 个答案:

没有答案