1
私はPubNub Apiとイオンプラットフォームを使ってwhatsappアプリケーションを作成しています。ただし、ionic.bundle.js:21157 TypeError:PubNub.publishは関数ではありません。以下は私のコードです。誰でも助けてくれますか?Ionic Pubnub chat in Angular:ionic.bundle.js:21157 TypeError:PubNub.publishは関数ではありません
var chat = angular.module('chat', ['pubnub.angular.service']);
chat.controller('chatController', ['$scope', '$state', '$rootScope',
'$stateParams', 'PubNub', '$http', '$ionicScrollDelegate',
function($scope, $state, $rootScope, $stateParams, PubNub, $http,
$ionicScrollDelegate){
var nickname = $stateParams.nickname;
var channel = $stateParams.channel;
$scope.messageContent = '';
$scope.messages = [];
$scope.goBack = function() {
$state.go('channels',{nickname: nickname, channel: channel});
}
PubNub.init({
publish_key:'',
subscribe_key:'',
ssl: true,
nickname: nickname
});
$scope.sendMessage = function() {
if (!$scope.messageContent ||
$scope.messageContent === '') {
return;
}
PubNub.publish({
channel: channel,
message: {
content: $scope.messageContent,
nickname: nickname
},
callback: function(m) {
console.log(m);
}
});
$scope.messageContent = '';
}
PubNub.ngSubscribe({channel: channel});
$rootScope.$on(PubNub.ngMsgEv(channel), function(event, payload) {
$scope.$apply(function() {
$scope.messages.push(payload.message);
$ionicScrollDelegate.scrollBottom();
console.log(payload.message);
});
});
}]);
正しい依存性注入(Pubnub)でも同じエラーが発生します。 –