无法通过Angular的调试访问函数

时间:2017-08-10 09:40:53

标签: angular debugging typescript rxjs

我使用Angular调试来测试我的项目的功能。我不明白为什么我的某些功能有效而其他功能无效。 这是我在控制台上写的内容:

ng.probe($0).componentInstance.threadService.__proto__.getThreadFromSubscription('tEcho')

以下是一个有效的函数示例:

openSettings(): void {
document.getElementById('outside').style.display = 'block';
document.getElementById('chat-threads').classList.toggle('display-settings');
}

虽然这个不起作用:

getThreadFromSubscription(threadId: string): Observable<Thread>{
  return this.threads
  .map( (threadDictionary: { [key: string]: Thread }) => {
    for (let key in threadDictionary) {
      if (threadDictionary[key].id == threadId)
        return threadDictionary[key];
    }
  });

这是一个错误:

Uncaught TypeError: Cannot read property 'map' of undefined

我像这样编辑我的变量线程:

this.threads = messageService.messages
  .map((messages: Message[]) => {
    const threads: { [key: string]: Thread } = {};
    messages.map((message: Message) => {
      threads[message.thread.id] = threads[message.thread.id] ||
        message.thread;

      const messagesThread: Thread = threads[message.thread.id];
      if (!messagesThread.lastMessage ||
        messagesThread.lastMessage.date < message.date) {
        messagesThread.lastMessage = message;
      }
    });
    return threads;
  });

和messageService.messages:

messages: Observable<Message[]>;

this.messages = this.updates
  .scan((messages: Message[],
         operation: IMessagesOperation) => {
      return operation(messages);
    },
    initialMessages)
  .publishReplay(1)
  .refCount();

我的印象是控制台不知道我在项目中初始化的一些变量。你有过这个问题吗?还有一个问题,你知道是否可以通过调试在我的组件中执行函数吗?

/////////////////////////////////////////////// ///////////////////////////////// 修改

我改述了我的问题。我使用angular的调试模式来根据我的控制台执行我的功能,我写这个:

ng.probe($0).componentInstance.chatService.__proto__.addNewMessage({
"id": "toto",
"body": "COUCOU", 
"author": "Toto"
})

当我执行我的功能时,它会显示错误,例如:

Uncaught TypeError: Cannot read property 'filter' of undefined

Uncaught TypeError: Cannot read property 'map' of undefined

我不明白为什么,因为当我正常运行这些工作时。

您知道Angular的模式调试中是否有参数?

0 个答案:

没有答案