无法读取属性';forEach&x27;在pubnub-angular2中

无法读取属性';forEach&x27;在pubnub-angular2中,angular,pubnub,Angular,Pubnub,我在Angular2中使用Pubnub 实际上它工作得很好,但在渲染几分钟后会出错。我不知道它为什么来 这是我的代码和截图 constructor(private router: Router, private navService: NavService, pubnubService: PubNubAngular) { var pubnubService = new PubNubAngular(); this.branchIdSave = localStorage.getIt

我在Angular2中使用Pubnub 实际上它工作得很好,但在渲染几分钟后会出错。我不知道它为什么来

这是我的代码和截图

constructor(private router: Router, private navService: NavService, pubnubService: PubNubAngular) {

    var pubnubService = new PubNubAngular();
    this.branchIdSave = localStorage.getItem('branchId');

    pubnubService.init({
      publishKey: p_key,
      subscribeKey: s_key
    });

    pubnubService.subscribe({
      channels: ['ADMIN-' + this.branchIdSave],
      withPresence: true,
      triggerEvents: ['message', 'presence', 'status']
    });

    pubnubService.getMessage('ADMIN-' + this.branchIdSave, function (msg) {
      this.newOrderCount = msg['message'].branchBadge['newOrderCount'];
      this.preservedOrderCount = msg['message'].branchBadge['preservedOrderCount'];
      this.waitingApplicantCount = msg['message'].branchBadge['waitingApplicantCount'];
    });
  }


  ngOnInit() {
    this.navService.getBadges(this.branchIdSave).subscribe(
      data => {
        this.newOrderCount = data.result.newOrderCount;
        this.preservedOrderCount = data.result.preservedOrderCount;
        this.waitingApplicantCount = data.result.waitingApplicantCount;
      }
    );
  }

  • 添加了错误消息
GET…tr=4&uuid=04434f7f-c14d-46ec-84ba-e382a3db1a11&pnsdk=PubNub JS Web%2F4.4.0 net::ERR\u EMPTY\u响应

error_handler.js:56 TypeError:无法读取未定义的属性“forEach” at Object.self.listener.(匿名函数)[as status]() 在 at Array.forEach(本机) 在e.value() 在e.(U重新连接回调() 在 在m() 在 在f.callback()处 在f。() 在f.r.emit() 在XMLHttpRequest.n.onreadystatechange()上 在XMLHttpRequest.wrapFn[as _onreadystatechange]() 在ZoneDelegate.invokeTask()上 在Object.onInvokeTask()处

  • 增加
已接收.affectedChannels.forEach((通道)=>{

此部分出错,无法读取未定义的属性“forEach”

从“../config.json”导入配置;
课堂模拟{
建造商(广播公司){
this.listener=null;
this.broadcaster=广播员;
this.broadcastChannel={};
}
/**
*初始化侦听器以广播所有事件
*
*@param{wrapper}实例
*/
initializeListener(实例){
if(this.listener==null){
让自我=这个;
self.listener={};
config.subscribe\u listener\u events\u to\u broadcast.forEach((event)=>{
self.listener[事件]=函数(已接收){
if(received.subscription&&self.broadcastChannels[received.subscription]&&self.broadcastChannels[received.subscription]。包括(事件)){
self.broadcaster.emit(事件、已接收、订阅、已接收);
如果(已接收。通道){
self.broadcaster.emit(事件,已接收。频道,已接收);
}
}
if(received.channel&&self.broadcastChannels[received.channel]&&self.broadcastChannels[received.channel]。包括(事件)){
self.broadcaster.emit(事件,已接收。频道,已接收);
}
如果(事件=='状态'){
如果(已收到。错误){
self.broadcaster.emitError(已接收);
}否则{
已接收.affectedChannels.forEach((通道)=>{
if(self.broadcastChannels[channel]&&self.broadcastChannels[channel]。包括(事件)){
self.broadcaster.emit(事件、频道、接收);
}
});
received.affectedChannelGroups.forEach((channelGroup)=>{
if(self.broadcastChannels[channelGroup]&&self.broadcastChannels[channelGroup]。包括(事件)){
self.broadcaster.emit(事件、频道组、接收);
}
});
}
}
};
});
instance.getOriginalInstance().addListener(this.listener);
}
}
/**
*向要广播的所有事件添加一组频道
*
*@param{[string]}通道
*@param{true |['message','presence','status']}触发事件
*/
addEventsBroadcast(频道、触发事件){
channels.forEach((channel)=>{
如果(triggerEvents的类型=='boolean'){
this.broadcastChannels[channel]=config.subscribe\u listener\u events\u to\u broadcast;
}else if(Array.isArray(triggerEvents)){
此.broadcastChannel[channel]=[];
triggerEvents.forEach((触发器)=>{
if(config.subscribe_listener_events_to_broadcast.includes(触发器)){
此.broadcastChannel[channel].push(触发器);
}
});
}
});
}
/**
*从要广播的所有事件中删除一组频道
*
*@param{[string]}通道
*/
removeEventBroadcast(频道){
channels.forEach((channel)=>{
if(此.broadcastChannel[频道]){
删除此。广播频道[频道];
}
});
}
/**
*为广播公司启用一组或一组频道
*
*@param{object}args
*/
enableEventsBroadcast(args){
if(参数通道){
this.addEventsBroadcast(args.channels,args.triggerEvents);
}
if(参数通道组){
this.addEventsBroadcast(args.channelGroups,args.triggerEvents);
}
}
/**
*禁用广播机构的一组或一组频道
*
*@param{object}args
*/
禁用事件广播(args){
if(参数通道){
此.removeEventBroadcast(args.channels);
}
if(参数通道组){
此.removeEventBroadcast(args.channelGroups);
}
}
}
module.exports=Mock;
module.exports.Mock=Mock;
//////////////////
//网页页脚
//./~/publinub-angular2/src/mock.js
//模块id=1075

//module chunks=3
文本的屏幕截图很难阅读,无法解析/搜索/复制。你能将输出作为文本包含在上面的帖子中吗?@CraigConover谢谢你的回复!我添加了错误消息。我不确定它是否能帮助你理解我的错误。@CraigConover我添加了导致错误的源代码。请检查它out:)这可能意味着
已接收。AffectedChannel
未定义(null,nil)或不是您期望的类型。请检查它的值,看看它是否有值,或者是否如我所怀疑的那样未定义。@CraigConover谢谢,但问题不是我的代码。它来自pubnub代码…我使用pubnub错误吗?