javascript - 使用服务器发送的事件访问函数外的范围
问题描述
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
函数外部,但它给了我未定义的。如何在函数之外访问它
解决方案
推荐阅读
- ios - 无法使用 App Manager 角色在 iTunes Connect 中创建新应用
- windows - 从 Git 推送和拉取后,目录符号链接更改为文件符号链接
- android - 如何将前台服务降级为后台,删除服务通知
- javascript - 从地图返回值
- angular - 如何在angular7中使用EventEmitter
- masm - 向内存地址添加偏移量
- mysql - 使用 LOAD DATA 导入 JSON 数据并在导入时指定日期数据类型
- vba - 如何在主表单的特定标签页中添加现有表单?
- openthread - 是否有用于 openthread 的 .net 实现
- domain-driven-design - 聚合为服务