is it possible to use getReactively on $rootScope variables?

300 views Asked by At

I have a case that I want to update the ui based on the user so if a user was log-out and log-in as different user, a score of the user in the ui is changed. The way I thought about doing it is by looking at $rootScope.currentUser.

from my testing it seems like there is some kind of access to the $rootScope, but it is not getting updated on user change (unless I have a bug in my code). here is the relevant code:

$meteor.autorun($scope, function() {
            if (null !== $rootScope.currentUser) {
                $scope.userForScore = $scope.$meteorObject(Userinfo, {user_id: $scope.getReactively('currentUser')._id});//$rootScope.currentUser._id
            }
        });

    $scope.userScore = function(){
        if ($scope.userForScore === undefined || $scope.userForScore.score === undefined) {
            return 1;
        }
        return $scope.userForScore.score;
    };

Userinfo - is a collection I created in the server.

2

There are 2 answers

1
Urigo On BEST ANSWER

Yes it is possible and it works exactly like you did it.

Your problem was unrelated to getReactively, I've created a pull request to your repo to fix it: https://github.com/Urigo/angular-meteor/issues/415#issuecomment-113925910

0
Tally Barak On

You can use Meteor.user() which is a reactive var. No need to add an additional layer of watchers.