M
M
mortyy2017-04-04 16:42:45
JavaScript
mortyy, 2017-04-04 16:42:45

How to properly implement infinite scroll in angular?

Now there is this code:

$elem.scroll(function () {
        if ($ctrl._loading) return;
        if ($elem.scrollTop() - 50< 0) {
          $ctrl.onScrolled.call($ctrl.context)
        }
      })

as a result, when loading data, I remain at the very top, but I need the scroll to be at the place where the data loading began. (vk chat, etc.)
I think that you need to remember the position and scroll after the new data is displayed
var sh = raw.scrollHeight
....
 raw.scrollTop = raw.scrollHeight - sh;

Tried through
ng-init=($last?finished():null)
but it doesn't work.
Adding data:
this.getMessages(req)
        .then(({items}) => {
          this.messages.unshift(...items.reverse());
          this.isGettingScrolledMessages = false;
          this.$rootScope.silent = true;
        });

How do you know that all the data is displayed and you can return to the previous place or maybe there are better options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Kalashnikov, 2017-04-04
@mortyy

try $timeout

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question