我正在尝试在连接事件中调用我的角度注入实例或本地实例。但是,每当我进行引用时,就会在运行时抛出错误。
ifCall = false;
constructor(private rtc: WebrtcService, public api: ApiService, private toastr: ToastrService) {
}
someFunction(){
connection.checkPresence(x[0].roomId, function(isRoomEists, roomid) {
if(isRoomEists) {
connection.join(roomid);
if(connection.getAllParticipants().length === 0){
connection.getAllParticipants().forEach(function(participantId) {
connection.disconnectWith(participantId);
});
// ERROR
this.api.deleteRooms(roomid);
}
}
else {
// ERROR
this.ifCall = false;
this.api.deleteRooms(roomid);
}
});
}
``
core.js:15724 ERROR TypeError: Cannot set property 'ifCall' of undefined
at home.component.ts:77
at r.<anonymous> (rtc.min.js:18)
at r.onack (socket.io.js:8)
at r.onpacket (socket.io.js:8)
at r.<anonymous> (socket.io.js:8)
at r.emit (socket.io.js:6)
at r.ondecoded (socket.io.js:6)
at a.<anonymous> (socket.io.js:8)
at a.r.emit (socket.io.js:6)
at a.add (socket.io.js:6)