javascript - Angular 2 load data once and filter Observable locally -


i have angular 2 app , i've managed set input on page autocomplete calls out api , sever side filtering , returning of values. lot tutorial found here.

now, i'm trying few more inputs page, don't need filter on server side. inefficient. better values when component loads , filter in component. causing me no shortage of problems. have api call returns 3 string arrays need. getting angular service using standard method so:

getformfilters(): observable<formfiltermodel> {     return this._http.get(this.baseurl+this.getformfilterspath)       .map(res => res.json() formfiltermodel);   } 

the model:

export interface formfiltermodel {     array1: string[];     array2: string[];     array3: string[]; } 

this works fine, , observable back. i'm stuck how filter these 3 arrays locally? have inputs wired form controls server side filtering input. can't figure out how actual arrays in observable filter them. here's i'm @ code:

this.filteredarray1$ = this.searchform.controls.array1search.valuechanges       .debouncetime(300)       .distinctuntilchanged()       .switchmap(term => //some filtering here of formfiltermodel$ return subset of array1 based on input) 

i can filter array via regexp fine, getting actual array in observable can't seem do.

subscribe api call store result in component. then, filter arrays in valueschanges.map.

ngoninit() {   this.getformfilters().subscribe(formfilters => {     this.formfilters = formfilters;   });    this.filteredarray1$ =  this.searchform.controls.array1search.valuechanges     .debouncetime(300)     .distinctuntilchanged()     .map(search => this.formfilters.array1.filter(value => matches(value, search))) } 

Comments