问题描述
我有,我想因此如果用户是注销和登录不同的用户,在UI用户的比分改变为更新基于用户界面的情况。我想过做它的方式是看 $ rootScope.currentUser
。
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
.
这是我的测试中好像有某种访问$ rootScope,但它是没有得到用户的改变而更新(除非我有我的code错误)。这里是有关code:
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.
推荐答案
是的,它是可能的,它的工作原理完全一样,你做到了。
Yes it is possible and it works exactly like you did it.
您的问题是无关getReactively,我创建了一个拉请求您的回购来解决它:
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
这篇关于是否有可能在$ rootScope变量使用getReactively?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!