问题
I have the following event listener in my AngularJS Controller (as shown in the PubNub SDK docs) that fires multiple times on one message if the browser is refreshed after the message comes in.
But the data
is empty after the original call to Pubnub.getMessageEventNameFor()
so besides for just checking data
(which seems like a hack covering up another issue), how/why is this function being repeatedly called?
$scope.$on(Pubnub.getMessageEventNameFor($scope.myChannel), function(ngEvent, data) {
$scope.$apply(function() {
processMessage(data.message);
});
});
Is there a way to prevent this listener from firing multiple times?
UPDATE: The multiple fires are each associated with a previous message, as opposed to multiple firings of the same message. This is sounding more and more like an Pubnub AngularJS SDK issue.
来源:https://stackoverflow.com/questions/42440256/pubnub-angularjs-service-fires-repeatedly