【问题标题】:Chrome app - error when call channel.open() using GAE channel javascript APIChrome 应用程序 - 使用 GAE 通道 javascript API 调用 channel.open() 时出错
【发布时间】:2014-05-12 02:21:03
【问题描述】:

我的服务器在谷歌应用引擎上运行,我的客户端是一个使用 Angular 框架的 chrome 应用。我正在尝试实现 GAE 的 Channel Java API 服务。 我的问题是当 channel.open() 被称为 angular 在控制台上显示此错误:'beforeunload 在打包的应用程序中不可用。下面是我用控制器编写的代码:

var channel = new goog.appengine.Channel(token);
console.log("channel");
var socket = channel.open();
console.log("socket");
socket.onopen = function(){
    console.log(open);
};

console.log("on open");
socket.onmessage = function(msg){
    console.log("Message: "+msg);
}

(控制台显示“通道”但不显示“套接字”)

【问题讨论】:

    标签: javascript angularjs google-app-engine google-chrome-app channel


    【解决方案1】:
    • 创建一个 AngularJS 服务来保存聊天列表。这是 不是必需的,但它是共享 observable 的推荐方式 控制器之间的数组(这意味着双向数据绑定)。
    • 在该服务中启动 Channel API。现在有诀窍了:要将可观察数组的修改推送到控制器,我们需要使用 $rootScope 方法。

    参考 - app-engine-channel-api-and-angularjs

    【讨论】:

    • 我在 channel.js 中评论了“beforeunload”行。我的项目现在正在运行,希望以后没有大问题。无论如何感谢您的参考
    猜你喜欢
    • 2018-02-05
    • 2017-09-21
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 2012-07-19
    • 2017-06-06
    • 2022-07-20
    • 2017-07-20
    相关资源
    最近更新 更多