angularjs - $scope.$apply after $scope.$on -
i using $broadcast pattern outlined here controllers listen service's state.
for example, here listen service's busy/unbusy state set mouse cursor.
//our service function startrunning(){ $rootscope.$broadcast("busy"); } function stoprunning(){ $rootscope.$broadcast("unbusy"); } //our controller $scope.$on("busy", function(){ $scope.state = "busy"; }); $scope.$on("unbusy", function(){ $scope.state = "ready" }); html
<div ng-controller = "myctrl" ng-state = "state"/> css:
.busy{ cursor: wait; } .ready { cursor:auto; } the problem cursor doesn't change immediately. requires me move mouse, imagine trigger $digest cycle, before cursor changes.
i can fix
$scope.$apply($scope.state = "ready"); but throw up:
error: [$rootscope:inprog] $digest in progress errors.
what best way deal this?
edit: here's working jsfiddle: http://jsfiddle.net/hb7lu/23512/
the issue appears using non-angular timeout/asynchronous methods. (ie. issue doesn't appear if using $timeout, appear if using settimeout;
Comments
Post a Comment