Javascript ';jsonp';未定义(带PubNub的AngluarJS)
我正在学习如何使用PubNub库创建聊天应用程序,当我导航到可以创建聊天室或加入聊天的页面时,会出现此错误Javascript ';jsonp';未定义(带PubNub的AngluarJS),javascript,angularjs,scope,pubnub,Javascript,Angularjs,Scope,Pubnub,我正在学习如何使用PubNub库创建聊天应用程序,当我导航到可以创建聊天室或加入聊天的页面时,会出现此错误 TypeError: Cannot read property 'jsonp' of undefined at window.PUBNUB.CREATE_PUBNUB (https://cdn.pubnub.com/pubnub-3.7.20.js:2719:14) at new SELF (https://cdn.pubnub.com/pubnub
TypeError: Cannot read property 'jsonp' of undefined
at window.PUBNUB.CREATE_PUBNUB (https://cdn.pubnub.com/pubnub-3.7.20.js:2719:14)
at new SELF (https://cdn.pubnub.com/pubnub-3.7.20.js:2739:16)
at a.exports.e.value (http://localhost:9000/bower_components/pubnub-angular/dist/pubnub-angular-3.1.0.min.js:16:64)
at Object.b.init (http://localhost:9000/bower_components/pubnub-angular/dist/pubnub-angular-3.1.0.min.js:4:87)
at new <anonymous> (http://localhost:9000/scripts/controllers/main.js:13:15)
at invoke (http://localhost:9000/bower_components/angular/angular.js:4535:17)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4543:27)
at http://localhost:9000/bower_components/angular/angular.js:9395:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:977:26)
at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:9039:9) <div ng-view="" class="ng-scope" data-ng-animate="1">(anonymous function) @ angular.js:12722(anonymous function) @ angular.js:9490invokeLinkFn @ angular.js:9041nodeLinkFn @ angular.js:8533compositeLinkFn @ angular.js:7929publicLinkFn @ angular.js:7809boundTranscludeFn @ angular.js:7947controllersBoundTransclude @ angular.js:8560update @ angular-route.js:935Scope.$broadcast @ angular.js:16573(anonymous function) @ angular-route.js:619processQueue @ angular.js:14991(anonymous function) @ angular.js:15007Scope.$eval @ angular.js:16251Scope.$digest @ angular.js:16069Scope.$apply @ angular.js:16359done @ angular.js:10791completeRequest @ angular.js:10989requestLoaded @ angular.js:10930
TypeError:无法读取未定义的属性“jsonp”
在window.PUBNUB.CREATE_PUBNUB(https://cdn.pubnub.com/pubnub-3.7.20.js:2719:14)
在新的自我(https://cdn.pubnub.com/pubnub-3.7.20.js:2739:16)
以a.e.价值(http://localhost:9000/bower_components/pubnub-角度/距离/pubnub-angular-3.1.0.min.js:16:64)
在Object.b.init(http://localhost:9000/bower_components/pubnub-角度/距离/pubnub-angular-3.1.0.min.js:4:87)
在纽约(http://localhost:9000/scripts/controllers/main.js:13:15)
在调用时(http://localhost:9000/bower_components/angular/angular.js:4535:17)
在Object.instantiate(http://localhost:9000/bower_components/angular/angular.js:4543:27)
在http://localhost:9000/bower_components/angular/angular.js:9395:28
在链接(http://localhost:9000/bower_components/angular-路线/角度路线.js:977:26)
在肯德基(http://localhost:9000/bower_components/angular/angular.js:9039:9)(匿名函数)@angular.js:12722(匿名函数)@angular.js:9490invokeLinkFn@angular.js:9041nodeLinkFn@angular.js:8533 CompositeLinkFn@angular.js:7929publicLinkFn@angular.js:7809boundTranscludeFn@angular.js:7947controllersBoundTransclude@angular.js:8560update@angular route.js:935Scope.$broadcast@angular.js:16573@angular route.js:619processQueue@angular.js:14991(匿名函数)@angular.js:15007Scope.$eval@angular.js:16251Scope.$digest@angular.js:16069Scope.$apply@angular.js:16359done@angular.js:10791completeRequestRequestLoaded@angular.js:10930
不知道这意味着什么,需要帮助吗
我的代码在这里angular.module('pnChatApp')
.controller('MainCtrl', ['$scope', '$rootScope', '$location', 'Pubnub', function ($scope, $rootScope, $location, Pubnub) {
var _ref;
if (!Pubnub.init()) {
$location.path('/join');
}
$scope.controlChannel = '__controlChannel';
$scope.channels = [];
//Publish Chat
$scope.publish = function() {
if (!$scope.selectedChannel) {
return;
}
Pubnub.ngPublish({
channel: $scope.selectedChannel,
message: {
text: $scope.newMessage,
user: $scope.data.username
}
});
return $scope.newMessage = '';
};
//Create Channel
$scope.createChannel = function() {
var channel;
console.log('Creating Channel...');
channel = $scope.newChannel;
$scope.newChannel = '';
Pubnub.ngGrant( {
channel: channel,
read: true,
write: true,
callback: function(){
return console.log(channel + 'All Set', arguments);
}
});
Pubnub.ngGrant( {
channel: channel + '-pnpres',
read: true,
write: false,
callback: function(){
return console.log(channel + 'Presence All Set', arguments);
}
});
Pubnub.ngPublish({
channel: $scope.controlChannel,
message: channel
});
return setTimeout(function() {
$scope.subscribe(channel);
return $scope.showCreate = false;
}, 100);
};
$scope.subscribe = function(channel) {
var _ref;
console.log('Subscribing...');
if (channel === $scope.selectedChannel) {
return;
}
if ($scope.selectedChannel) {
Pubnub.ngUnsubscribe({
channel: $scope.selectedChannel
});
}
$scope.selectedChannel = channel;
$scope.messages = ['Welcome to ' + channel];
Pubnub.ngSubscribe({
channel: $scope.selectedChannel,
state: {
"city": ((_ref = $rootScope.data) !== null ? _ref.city : void 0) || 'unknown'
},
error: function() {
return console.log(arguments);
}
});
$rootScope.$on(Pubnub.ngPrsEv($scope.selectedChannel), function(ngEvent, payload) {
return $scope.$apply(function() {
var newData, userData;
userData = Pubnub.ngPresenceData($scope.selectedChannel);
newData = {};
$scope.users = Pubnub.map(Pubnub.ngListPresence($scope.selectedChannel), function(x) {
var newX;
newX = x;
if (x.replace) {
newX = x.replace(/\w+__/, "");
}
if (x.uuid) {
newX = x.uuid.replace(/\w+__/, "");
}
newData[newX] = userData[x] || {};
return newX;
});
return $scope.userData = newData;
});
});
Pubnub.ngHereNow({
channel: $scope.selectedChannel
});
$rootScope.$on(Pubnub.ngMsgEv($scope.selectedChannel), function(ngEvent, payload) {
var msg;
msg = payload.message.user ? "[" + payload.message.user + "]" + payload.message.text : payload.message.text;
return $scope.$apply(function() {
return $scope.messages.unshift(msg);
});
});
return Pubnub.ngHistory({
channel: $scope.selectedChannel,
auth_key: $scope.authKey,
count: 500
});
};
Pubnub.ngSubscribe({
channel: $scope.controlChannel
});
$rootScope.$on(Pubnub.ngMsgEv($scope.controlChannel), function(ngEvent, payload) {
return $scope.$apply(function() {
if ($scope.channels.indexOf(payload.message) < 0) {
return $scope.channels.push(payload.message);
}
});
});
return Pubnub.ngHistory({
channel: $scope.controlChannel,
count: 500
});
$scope.channels = 'TheWaitingRoom';
return $scope.createChannel();
}]);
angular.module('pnChatApp'))
.controller('MainCtrl'、['$scope','$rootScope','$location','Pubnub',函数($scope,$rootScope,$location,Pubnub){
var_ref;
如果(!publinub.init()){
$location.path('/join');
}
$scope.controlChannel='\uu controlChannel';
$scope.channels=[];
//发布聊天
$scope.publish=函数(){
如果(!$scope.selectedChannel){
返回;
}
发布({
频道:$scope.selectedChannel,
信息:{
text:$scope.newMessage,
用户:$scope.data.username
}
});
返回$scope.newMessage='';
};
//创建频道
$scope.createChannel=function(){
var通道;
log('Creating Channel…');
channel=$scope.newChannel;
$scope.newChannel='';
Pubnub.ngGrant({
频道:频道,,
读:没错,
写:是的,
回调:函数(){
返回console.log(通道+'All Set',参数);
}
});
Pubnub.ngGrant({
通道:通道+'-pnpres',
读:没错,
写:错,
回调:函数(){
返回console.log(通道+'Presence All Set',参数);
}
});
发布({
通道:$scope.controlChannel,
信息:频道
});
返回setTimeout(函数(){
$scope.subscribe(频道);
返回$scope.showCreate=false;
}, 100);
};
$scope.subscribe=函数(通道){
var_ref;
log('Subscribing…');
如果(通道==$scope.selectedChannel){
返回;
}
如果($scope.selectedChannel){
Pubnub.ngUnsubscribe({
频道:$scope.selectedChannel
});
}
$scope.selectedChannel=频道;
$scope.messages=[“欢迎来到”+频道];
订阅({
频道:$scope.selectedChannel,
声明:{
“城市”:((_ref=$rootScope.data)!==null?_ref.city:void 0)| |“未知”
},
错误:函数(){
返回console.log(参数);
}
});
$rootScope.$on(publinub.ngPrsEv($scope.selectedChannel),函数(ngEvent,有效负载){
返回$scope.$apply(函数(){
var newData,userData;
userData=publinub.ngPresenceData($scope.selectedChannel);
newData={};
$scope.users=Pubnub.map(Pubnub.ngListPresence($scope.selectedChannel),函数(x){
var-newX;
newX=x;
如果(x.更换){
newX=x.replace(/\w+\uuuu/,“”);
}
if(x.uuid){
newX=x.uuid.replace(/\w+\uuuu/,“”);
}
newData[newX]=userData[x]||{};
返回newX;
});
返回$scope.userData=newData;
});
});
Pubnub.ngHereNow({
频道:$scope.selectedChannel
});
$rootScope.$on(publinub.ngMsgEv($scope.selectedChannel),函数(ngEvent,有效负载){
var-msg;
msg=payload.message.user?”[“+payload.message.user+”]“+payload.message.text:payload.message.text;
返回$scope.$apply(函数(){
返回$scope.messages.unshift(msg);
});
});
返回publinub.ngHistory({
频道:$scope.selectedChannel,
auth_key:$scope.authKey,
计数:500
});
};
订阅({
通道:$scope.controlChannel
});
$rootScope.$on(publinub.ngMsgEv($scope.controlChannel),函数(ngEvent,payload){
返回$scope.$apply(函数(){
if($scope.channels.indexOf(payload.message)<0){
返回$scope.channels.push(payload.message);
}
});
});
返回publinub.ngHistory({
通道:$scope.controlChannel,
计数:500
});
$scope.channels='TheWaitingRoom';
返回$scope.createChannel();
}]);
jsonp错误的原因是publinub.init
具有必需的选项参数
Pubnub.init({ publish_key: 'your pub key', subscribe_key: 'your sub key' });
您似乎正在注入不存在的
Pubnub
服务。从那时起,您应该访问window.PUBNUB
global object我尝试了,但没有成功