I got the Typeahead working using Angular 8 and ng-bootstrap. However, I would like the empId to come from a JSON file as there's over 10,000 entries. Currently, I have this:
<input type="text" [(ngModel)]="model" [ngbTypeahead]="search"/>
.TS file:
import {Component} from '@angular/core';
import {Observable} from 'rxjs';
import {debounceTime, distinctUntilChanged, map} from 'rxjs/operators';
const empId = ['643200','987900','043100','049400','189700','240800','617600','228700','188600','631200','695000','029500','626500','199700','619300','995300','123700','619400','230200','017300','237800'];
@Component({
selector: 'ngbd-typeahead-basic',
templateUrl: './typeahead-basic.html',
styles: [`.form-control { width: 300px; }`]
})
export class NgbdTypeaheadBasic {
public model: any;
search = (text$: Observable<string>) =>
text$.pipe(
debounceTime(200),
distinctUntilChanged(),
map(term => term.length < 2 ? []
: empId.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10))
)
}
FYI, the JSON file is located in the same server at a location ../path/file.json
in the structure:
[
{
"empId": "643200"
},
{
"empId": "987900"
},
{
"empId": "043100"
},
{
"empId": "049400"
},
{
"empId": "189700"
}
]
Again, PS: empId in the JSON file has over 10,000+ entries. This is just an example.