0

这是我要解决的问题。

我有一个window.open功能打开一个小窗口,供用户使用他们选择的社交网络登录/注册。用户登录后,我希望关闭小窗口并$scope更新原始父窗口,而无需刷新页面。

我这样做的全部目标是不中断用户对网站的体验。该站点是一个音乐站点,因此如果用户正在听一首歌曲并且页面重新加载,他们将失去在站点中的位置并最终不开心。

我想就是这样。

app.controller('MainCtrl', [

  $scope.loginTrigger = function() {
    window.open("http://www.url.com/login", "_blank", "toolbar=yes, scrollbars=yes, resizable=no, top=0, left=100, width=1000, height=600");
  }

  if ($location.hash()) {
     $http({
      method: 'POST',
      url: '/users/oauth_complete/',
      data: data,
     }).success(function(data){
        if(!data.success){
         $window.location.href = '/usersetup';
        }else {
         $scope.LoggedInUser = data;
         storage.set('LoggedInUser', data);

         //Here is my current code: Small window closes and the parent page reloads but I don't want to use refresh as it will interrupt the user experience.
         window.close();
         window.opener.location.reload();
        }
     },"JSON");
  };

}]);
4

1 回答 1

0

您可以使用 $emit 和 $on 在类之间“交谈”

在您的登录控制器中,您将使用 $emit。

$scope.$emit('eventName', myData);

然后在您的另一个控制器中,您将使用 $on 函数进行监听:

$scope.$on('eventName', function(event, data) { console.log(data); });
于 2014-12-30T17:43:35.053 回答