Angular for循环上的迭代

Angular for循环上的迭代,angular,loops,typescript,for-loop,rxjs,Angular,Loops,Typescript,For Loop,Rxjs,我正在尝试根据用户输入的数据创建搜索栏 为此,我从用户检索数据。我创建一个For循环来迭代我的所有线程。然后比较这两个值: threads: BehaviorSubject<{[key: string]: Thread }> = new BehaviorSubject({}); searchUser(): Observable<Thread> { var str; var element = document.getElementById('chat-window-in

我正在尝试根据用户输入的数据创建搜索栏

为此,我从用户检索数据。我创建一个For循环来迭代我的所有线程。然后比较这两个值:

threads: BehaviorSubject<{[key: string]: Thread }> = new BehaviorSubject({});

searchUser(): Observable<Thread> {
var str;
var element = document.getElementById('chat-window-input');

if(element != null) {
  str = (element as HTMLInputElement).value;
}
else {
  str = null;
}

return this.threads.map((threadDictionary: {[key: string]: Thread}) => {
  for( let key in threadDictionary ) {
    console.log("key", threadDictionary[key]);

    if(threadDictionary[key].participants[0].name.startsWith(str)) {
      return threadDictionary[key];
    }
  }
});
}
然后我把它贴出来:

<div class="new-chat-window">
  <div class="search-bar">
    <i class="fa fa-search"></i>
    <input type="text"
           class="new-chat-window-input"
           name="chat-window-input"
           id="chat-window-input"
           placeholder="Rechercher"
           (keyup)="threadService.displaySearchUser()"/>
  </div>

  <div class="list-container">
    <list-user
      *ngFor="let thread of threadService.searchThreads | async"
      [thread]="thread">
    </list-user>
  </div>
</div>

我的问题是我只上最后一项。当我在控制台中显示“threadDictionnary[key]”时,它不会改变

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 编辑 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

我正在用一些细节编辑我的帖子。当我在构造函数循环中运行我的
this.displaySearchUser()
函数时,这对3个不同的元素都很好

我可以再次运行它吗,它只在一个元素上迭代

这是我的控制台的图片;前4行对应于我的函数的第一次启动。 然后,下一行对应于my函数的第二次运行:

<div class="new-chat-window">
  <div class="search-bar">
    <i class="fa fa-search"></i>
    <input type="text"
           class="new-chat-window-input"
           name="chat-window-input"
           id="chat-window-input"
           placeholder="Rechercher"
           (keyup)="threadService.displaySearchUser()"/>
  </div>

  <div class="list-container">
    <list-user
      *ngFor="let thread of threadService.searchThreads | async"
      [thread]="thread">
    </list-user>
  </div>
</div>