Reactive-Extensions / rx.angular.js

AngularJS Bindings for RxJS
Other
827 stars 89 forks source link

safeApply should work on scopes where $root is not set #147

Open RaviDesai opened 8 years ago

RaviDesai commented 8 years ago

There are some cases where I have a $scope variable where $root is not set: it isn't set in root scopes, and is not guaranteed in non-isolate scopes more info here- http://stackoverflow.com/questions/22216441/what-is-the-difference-between-scope-root-and-rootscope).

In these cases safeApply will fail to operate correctly due to this line: https://github.com/Reactive-Extensions/rx.angular.js/blob/master/src/safeApply.js#L14. I would like to see this line to be rewritten as:

($scope.$$phase || ($scope.$root && $scope.$root.$$phase)) ?
            onNext(data) :
            $scope.$apply(function () { onNext(data); });

or something similar so it would not fail incorrectly in these cases.