I am currently working on implementing a feature that detects whether the user is typing or not. I need to determine when the user has stopped typing for at least 3 seconds in order to perform certain actions. I have successfully detected when the user starts typing using the following code snippet:
ngOnChanges(searchValue: string) {
if (!this.searchChangeObserver) {
Observable.create(observer => {
this.searchChangeObserver = observer;
}).debounceTime(3000)
.subscribe((data) => {
if (data) {
typingStuff();
}
else {
notTypingStuff();
}
});
this.searchChangeObserver.next(searchValue);
}
}
}
Now, I need to find a way to detect when the user stops typing so that I can execute the notTypingStuff()
function.
Is there a simpler method to achieve this?
EDIT
In addition to the above code snippet, I am also utilizing the following code:
constructor(){
this.modelChanged
.debounceTime(300)
.subscribe((data) => {
if (data) {
typingStuff();
}
else {
notTypingStuff();
}
});
}
However, I still need to determine when the user stops typing for 3 seconds to trigger the notTypingStuff()
function as well.