javascript - Weird `$evalAsync` behaviour -


abstract

hi, i'm trying manipulate scroll logic of angular application (by hand), since there no such thing onloaded event in angular, trying accomplish within $interval loop. worked ui flickering, looked scroll first goes way , down again making terrible. i've started looking solution problem , found this answer. in said have looking $evalasync capable of queueing operation before ui it's rendering. lead me following code:

    var restorescroll = function (scroll) {         angular.element($window).scrolltop(scroll);          var fn = function () {             debugger;             var value = angular.element($window).scrolltop();              if (value !== scroll) {                 angular.element($window).scrolltop(scroll);                  $rootscope.$evalasync(fn);             }         }          $rootscope.$evalasync(fn);     }; 

which hangs , shows misunderstanding of angular's $evalasync method.

question

according code above need method trying set scroll until succeeds, after when should stop, how do using $evalasync?

thank in advance!

==================

edit

ive managed make work, not without devils (the $$postdigest) in code, here goes:

    var restorescroll = function (scroll) {         angular.element($window).scrolltop(scroll);          var fn = function () {             var value = angular.element($window).scrolltop();              if (value !== scroll) {                 angular.element($window).scrolltop(scroll);                  $rootscope.$$postdigest(fn);             }         }          $rootscope.$$postdigest(fn);     }; 

is there better way?


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -