Boucle For sur un flux BehaviorSubject
Ma variable threads contient 3 éléments différents. Je veux créer une boucle For qui itère sur tous ses 3 éléments.
Code:
threads: Subject<{[key: string]: Thread }> = new BehaviorSubject({});
Voici ma fonction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| searchUser(): Observable<Thread> {
let element = document.getElementById('chat-window-input');
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];
}
}
});
} |
Cette fonction fonctionne qu'une seule fois. A son premier appel, elle itère bien sur les 3 éléments. Ensuite, elle n'itère plus que sur le dernier élément.
J'utilise Angular et TypeScript.