javascript-Angular中的Pubnub聊天
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-Angular中的Pubnub聊天,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2312字,纯文字阅读大概需要4分钟。
内容图文
![javascript-Angular中的Pubnub聊天](/upload/InfoBanner/zyjiaocheng/683/5ade9c24b61f4182a83de1ec6f5736ae.jpg)
我正在AngularJS应用程序中实现pubnub聊天.我正在追踪tutorial
问题是,如果我从头开始创建新的AngularJS应用程序,则聊天有效,但是如果我在现有应用程序中实现代码,则会出现此错误:
Missing Callback pubnub.min.js:1
而且我看不到我写的消息和应该收到的消息,但是我可以发送它们,并且可以在聊天的另一端看到这些消息.
你知道我该怎么解决吗?
编辑:这是pubnub聊天的控制器:
'use strict';
angular.module('myApp.appointments', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
}])
.controller('appointmentsCtrl', ["$rootScope", "$scope", "$http", "$timeout", "$cookies", "URL", "Pubnub", function($rootScope, $scope, $http, $timeout, $cookies, URL, Pubnub) {
$scope.sortType = 'name';
$scope.sortReverse = false;
$scope.sortType_s = 'time';
$scope.filterAppointments = false;
$scope.filterDate = '';
$scope.highlightRow = '';
$scope.$on('$routeChangeSuccess', function() {
var data = {
"token":$cookies.get('userToken'),
"hairdresser_id": $cookies.get('userId')
};
$http.post(URL.url + 'appointments', data).then(function(res){
$scope.app_list = res.data.appointments;
$scope.service_list = res.data.appointment_services;
$scope.customers_list = res.data.customers;
$scope.pending_number = res.data.pending;
});
data = {
"token":$cookies.get('userToken'),
"hairdresser_id": $cookies.get('userId')
};
$http.post(URL.url + 'monthly_earnings', data).then(function(res){
$rootScope.monthly_earnings = res.data.amount;
});
});
// Pubnub implementation
$scope.channel = "messages-channel";
$scope.uuid = _.random(100).toString();
Pubnub.init({
publish_key: MY_KEY,
subscribe_key: SUB_KEY,
ssl: true,
uuid: $scope.uuid
});
$scope.sendMessage = function() {
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) {
console.log(m);
}
});
$scope.messageContent = '';
}
$scope.messages = [];
Pubnub.subscribe({
channel: $scope.channel,
triggerEvent: ['callback']
});
$scope.$on(Pubnub.getMessageEventNameFor($scope.channel), function(ngEvent, m) {
$scope.apply(function() {
$scope.messages.push(m)
});
});
}]);
解决方法:
您在Pubub.subscribe函数的triggerEvents语句末尾忘记了s:
Pubnub.subscribe({
channel: $scope.channel,
triggerEvents: ['callback']
});
让我知道它是否解决了您的问题.
内容总结
以上是互联网集市为您收集整理的javascript-Angular中的Pubnub聊天全部内容,希望文章能够帮你解决javascript-Angular中的Pubnub聊天所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。