angularJS use theParam achieve memory function

Requirements: List paging, Jump details page, save the current page and search keywords. When returning from the details page, before returning to the pages and search the same keywords.

 

js:

mainApp.factory('theParam', function() {
    return {
        currentPage : 1,pageSize : 12,param:''
    };
});

mainApp.controller('listController', function($scope, $http,theParam) {
    
    $scope.currentPage = theParam.currentPage;
    $scope.pageSize = theParam.pageSize;
    scope.param $ = theParam.param; // search terms

    $scope.dataList;
    var dataObj = new Object(),
        reqUrl = "****";
    var initObj = function(){
        dataObj.pageNumber = $scope.currentPage;
        dataObj.pageSize = $scope.pageSize;
        dataObj.param = $ scope.param; 
    } 

  // ***** ****** omitted other
// the specified page to jump Case $ scope.goXpage = function (X) { initObj ();
     dataObj.pageNumber = X;
theParam.param = $ scope.param; // Save Image $http({ method : 'get', params : { param : $.toJSON(dataObj) }, data : {}, url : reqUrl }) .success(function(response, status, headers, config) {var rstate = response.result; if (rstate == "0") { var _data = response.message; $scope.dataList = _data.glist; $scope.currentPage = _data.pageNumber; theParam.currentPage = _data.pageNumber; //保存页数
       }
    else{ Showbo.Msg.alert('fail: '+response.error); } }) .error(function(response, status, headers, config) { Showbo.Msg.alert('error: '+response.error); }); }; }

Guess you like

Origin www.cnblogs.com/linjiangxian/p/12123270.html