【发布时间】:2018-08-11 02:16:10
【问题描述】:
我得到错误
“类型'typeof ChatEngineCore'上不存在属性'create'”和
“类型'typeof ChatEngineCore'上不存在属性'plugin'”
当我尝试在 PubNub Angular2 Chatbot 教程中调用 ChatEngineCore.create 和 ChatEngineCore.plugin 时。
有什么想法吗?我错过了一些简单的东西吗?这是我直接从 PubNub 的教程中复制的代码:
import { Injectable } from '@angular/core';
import { ChatEngineCore } from 'chat-engine';
@Injectable()
export class ChatEngine {
instance: any;
create: any;
plugin: any;
me: any = { state: {} };
chat: any = {};
chats: any[] = [];
constructor() {
// Make sure to import ChatEngine first!
this.instance = ChatEngineCore.create({
publishKey: 'MY-PUBLISH-KEY',
subscribeKey: 'MY-SUBSCRIBE-KEY'
},
{
debug: true,
globalChannel: 'chat-engine-angular2-simple'
});
this.create = ChatEngineCore.create.bind(this);
this.plugin = ChatEngineCore.plugin;
}
newChat(user) {
// define a channel
let chat = new Date().getTime();
// create a new chat with that channel
let newChat = new this.instance.Chat(chat);
// we need to auth ourselves before we can invite others
newChat.on('$.connected', () => {
// this fires a private invite to the user
newChat.invite(user);
// add the chat to the list
this.chats.push(newChat);
});
}
}
【问题讨论】:
-
能否提供教程链接和您使用的ChatEngine版本?