Wednesday, 15 January 2014

AngularJS - Waiting for $$phase to become null -



AngularJS - Waiting for $$phase to become null -

in directive, create api call, info , render it. while render happening, (i.e. $digest running), want wait , something.

this implementation, doesn't work:

// assume i'm in callback function of $resource function(response) { // $scope.templates needs render $scope.templates = (_.isempty(response.warning)) ? response.data : []; var s = $scope.$watch('$$phase', function(v) { if (_.isnull(v)) { nowrunmynextawesomeaction() // silent $watch s(); } }); }

when console.log(v) within $watch, logs $diget , nil else. why? thought else might happening, tried log $$phase $timeout after 1s, , shows null. not running

so, found "a" solution; don't know if practice or not, relies on using $timeout. under impression using timers in javascript not recommended?

anyway, here how this:

// assume i'm in callback function of $resource function(response) { // $scope.templates needs render $scope.templates = (_.isempty(response.warning)) ? response.data : []; $timeout(function(){ nowrunmynextawesomeaction(); }); }

note $timeout has delay of zero. more information, please see here.

angularjs

No comments:

Post a Comment