Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在函数中保存旧参数_Angular_Typescript_Rxjs - Fatal编程技术网

Angular 在函数中保存旧参数

Angular 在函数中保存旧参数,angular,typescript,rxjs,Angular,Typescript,Rxjs,我创建了一个即时通讯器。我的函数cliked(线程)允许我单击讨论并查看此讨论。用户不能同时打开超过2个聊天窗口。 因此,当两个聊天窗口打开时(this.threadService.windows.length==2),我必须关闭第一个窗口以显示新窗口 然后,我必须将第一个窗口保存在变量中,以便将其作为函数closeOldThread(oldThread)的参数输入 //// 可能吗? 因为在我的例子中,oldThread是未定义的。它也不工作。当我在if循环(this.threadServic

我创建了一个即时通讯器。我的函数cliked(线程)允许我单击讨论并查看此讨论。用户不能同时打开超过2个聊天窗口。 因此,当两个聊天窗口打开时(this.threadService.windows.length==2),我必须关闭第一个窗口以显示新窗口

然后,我必须将第一个窗口保存在变量中,以便将其作为函数closeOldThread(oldThread)的参数输入

////

可能吗?
因为在我的例子中,oldThread是未定义的。

它也不工作。当我在if循环(this.threadService.windows.length==2)中测试变量(this.oldThread)时,它等于“未定义”…this.threadService.windows中存储了什么?类型为
线程的对象
?非常感谢,它可以工作!我没有想过要这样做。
clicked(thread: Thread): void {
    this.newWindow = true;
    if(this.threadService.windows.length === 2) {
        // get the previously opened chat window
       let oldThread = this.threadService.windows[0];            
       this.closeOldThread(oldThread);
    }
    if (!this.thread.isOpen) {
       thread = this.chatService.openThread(thread);
       this.chatService.setCurrentThread(thread);
       this.thread.isOpen = true;
    }
}
closeOldThread(thread: Thread): void {
 let index = this.threadService.windows.indexOf(thread);
 this.threadService.windows.splice(index, 1);
 this.thread.isOpen = false;
 this.newUser = false;
 this.newWindow = false;
}
clicked(thread: Thread): void {
    this.newWindow = true;
    if(this.threadService.windows.length === 2) {
        // get the previously opened chat window
       let oldThread = this.threadService.windows[0];            
       this.closeOldThread(oldThread);
    }
    if (!this.thread.isOpen) {
       thread = this.chatService.openThread(thread);
       this.chatService.setCurrentThread(thread);
       this.thread.isOpen = true;
    }
}