【发布时间】:2017-09-20 20:03:04
【问题描述】:
我正在使用带有 PHP 后端的 javascript pusher library (angularjs)。
js:
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('API_KEY', {
cluster: 'ap2',
encrypted: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function (data) {
common.flashMsg('success', data.message);
});
绑定和解绑代码:
$scope.workerStatus = function (status) {
if (status == 'available') {
common.flashMsg('success', "Welcome Again...!");
channel.bind('my-event', function (data) {
common.flashMsg('success', data.message);
});
} else {
common.flashMsg("error", "You're now offline. Good Bye.");
channel.unbind('my-event', function () {
common.flashMsg('success', data.message);
});
}
}
我想取消绑定channel,当用户注销并停止通知,但频道unbind 事件不起作用时,用户仍然能够收到通知。
我错过了什么?
【问题讨论】:
-
我传入了对不同函数的引用,所以调用失败,现在问题解决了,在
unbind的第二个参数中使用相同的函数
标签: javascript angularjs pusher