I've incorporated the typeahead feature from ng-bootstrap into my Angular 8 project, using this link as a reference: https://ng-bootstrap.github.io/#/components/typeahead/examples. While implementing a function provided in the library's examples, I encountered an error when one of the inputs turned out to be null.
Within my component class, there is a variable created through a function:
searchAutofill = (text$: Observable<string>) =>
text$.pipe(
debounceTime(200),
distinctUntilChanged(),
map(term => term.length < 1 ? []
: this.option.filter(v => v && v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 15))
)
The 'option' variable is an array of strings, like so:
[
"tom",
"bob",
"foo",
"emma",
null,
"john",
"hello",
"example"
]
Upon encountering the null value, the function throws an error: ERROR TypeError: "v is null"
. How can I modify the code to handle or ignore null values?