Pubnubチャンネルに正常に公開すると、メッセージの履歴と着信メッセージが表示されます。チュートリアル以下、私がメッセージを表示することができるよ次コントローラ(コンポーネント/チャット/ chat.controller.js)角度1 - es6を使用してPubnubからのメッセージ履歴と着信メッセージを取得する方法
/*jshint esnext: true */
'use strict';
class ChatController {
constructor($scope, $rootScope, Pubnub) {
this.cardTitle = "chat window";
$scope.messages = [];
$scope.channel = 'Channel-jlinog5q8';
$scope.messageContent = '';
Pubnub.init({
"publishKey": publishKey,
"subscribeKey": subscribeKey,
});
// Subscribe to messages channel
Pubnub.subscribe({
channel: $scope.channel,
triggerEvents: ['callback'],
});
// $scope.messageEvents = Pubnub.getMessageEventNameFor($scope.channel)
Pubnub.history({
channel:$scope.channel,
callback: function(payload){
console.log(payload);
$scope.messages.unshift(payload.message);
}
})
// Send the messages over PubNub Network
$scope.sendMessage = function() {
$scope.uuid = $rootScope.userInfo.first_name +' '+$rootScope.userInfo.last_name;
// Don't send an empty message
if (!$scope.messageContent ||
$scope.messageContent === '') {
return;
}
Pubnub.publish({
channel: $scope.channel,
message: {
content: $scope.messageContent,
sender_uuid: $scope.uuid,
date: new Date()
},
callback: function(m) {
debugger
},
error: function (error) {
debugger
console.log('Error:', error);
}
});
// Reset the messageContent input
$scope.messageContent = '';
}
// Listenning to messages sent.
$scope.$on(Pubnub.getMessageEventNameFor($scope.channel), function (ngEvent, envelope) {
$scope.$apply(function() {
debugger
// add message to the messages list
$scope.messages.unshift(envelope.message);
});
});
}
activate($rootScope, PubNub, $scope) {
}
}
ChatController.$inject = ['$scope', '$rootScope', 'Pubnub'];
export default ChatController;
を作成しました首尾公開が、私はここで、チャネル内のメッセージを見ることができません私は購読しています。
コンポーネント/チャット/ chat.html:私は問題が$scope.$on
であると信じているが、私はPubNub JavascriptのSDKのバージョンこの