My latest project involves creating a search bar that displays users whose first names start with the letter 'A' when the user presses 'A'. The functionality works as expected, but I've run into an issue when the search bar is empty. Instead of displaying no results, my program currently shows all users.
Below is an excerpt from my code to retrieve the user input value:
searchUser(): void {
let str;
let element = document.getElementById('chat-window-input');
if(element !== null) {
str = (element as HTMLInputElement).value;
}
else {
str = null;
}
}
I have been trying to implement a check for an empty field, but so far it hasn't made a difference. Here's what I've attempted:
if(str == null) {
this.searchArrayThreads = [];
}