Javascript 使用帐户用户界面';t刷新$account.currentUser

Javascript 使用帐户用户界面';t刷新$account.currentUser,javascript,angularjs,meteor,angular-ui-router,Javascript,Angularjs,Meteor,Angular Ui Router,我在一个页面中使用dotansimha:accounts-ui指令,使用api服务(如google)登录。在页面中,我有一个带有ng show=“$auth.currentUser”的div,如果没有登录用户,该div将隐藏该div。代码工作得很好,但是我必须刷新页面。目前,我正在home index.html页面中嵌入标记。如何使$auth.currentUser值主动检查其值?因此我最终解决了这个问题,但我不知道这是否是最佳做法 在我的html中,如果用户没有登录,我想隐藏两个链接。我使用n

我在一个页面中使用
dotansimha:accounts-ui
指令,使用api服务(如google)登录。在页面中,我有一个带有
ng show=“$auth.currentUser”
的div,如果没有登录用户,该div将隐藏该div。代码工作得很好,但是我必须刷新页面。目前,我正在home index.html页面中嵌入
标记。如何使$auth.currentUser值主动检查其值?

因此我最终解决了这个问题,但我不知道这是否是最佳做法

在我的html中,如果用户没有登录,我想隐藏两个链接。我使用
ng show=“$auth.currentUser”

在我的工具栏指令中,我添加了$watch逻辑,用于监视
$auth.currentUser
值的变化

  $scope.$watch('currentUser',function(newVal, oldVal){
    console.log(newVal, oldVal)
    if(newVal !== oldVal || typeof newVal !== typeof {}){
      location.reload()
      Meteor.loginWithSpotify(options, function(err){
        console.log(err || 'No error')
      }
    }
    console.log(newVal, oldVal)
  })
如果$auth.currentUser的值不等于$auth.currentUser的值,或者$auth.currentUser不是对象的类型,则此逻辑将重新加载页面,而授权后的currentUser是一个对象

EX:if(用户数据!==null){刷新页面}

希望这是清楚的