search

Home  >  Q&A  >  body text

angular.js - 查看详情以后,返回列表页没有停留在原先查看的地方-angularJS问题的解决办法?求大神指教

查看详情以后,返回列表页没有停留在原先查看的地方-angularJS问题的解决办法?求大神指教

黄舟黄舟2744 days ago592

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-05-15 16:55:07

    If your list page is a paginated page, then you need to save the page number of the page, maybe in the URL, then when you return, read the page number from the URL and load the data of that page number.
    If your list page is a very long page and you need to return to the original position, then you may need to abstract a service to record the user's position on this page, and read this every time you enter this page. service thenscrollTothat location.
    If your list page has no pagination and is not very long, it is actually best to just go back to the top of the page.

    For the case where the page is very long:

    js// PagePosition Service
    angular.module('app').factory('PagePosition', function() {
        var _top = 0;
        var _left = 0;
    
        return {
            getPosition: function() {
                return {
                    top: _top,
                    left: _left
                }
            },
            setPosition: function(top, left) {
                _top = top;
                _left = left;
            }
        }
    });
    

    Inject this service into the view or directive you need, modify the position in the user scroll event, read the position when returning to this page, and call scrollTo to position.

    However, I suggest that if the page is too long, it is best to display your list in pages, because even if you can return to the previous position when returning, the user experience is quite poor.

    reply
    0
  • Cancelreply