首页 > 解决方案 > 使用服务器发送的事件访问函数外的范围

问题描述

function loadFollowing()
    {  
      if(typeof(EventSource)  !="undefined")
      {  
        var source=new EventSource("load_following_process.php");       
        source.onmessage=function(event)
        {
            $scope.$apply(function () {
                $scope.allFollowing =JSON.parse(event.data)
            });
          }
      }
    }
loadFollowing()

我试图访问$scope.allFollowing函数外部,但它给了我未定义的。如何在函数之外访问它

标签: javascriptjqueryangularjsangularserver-sent-events

解决方案


推荐阅读