Angular 2: How to use Observable filter

后端 未结 2 1313
栀梦
栀梦 2020-12-14 12:06

I have a service that calls the API like this:

return this._http
        .post(appSettings.apiUrl + \'SomeController/SomeAction\', params, {withCredentials:          


        
2条回答
  •  眼角桃花
    2020-12-14 12:53

    Here another sample based on @martin's answer:

      public searchMediData(searchtearm: string) : Observable 
      {  
    
        return this.http
                   .get(this.url)
                   .map(response => { 
                      let data = response.json();
                      let medidata = data as MediData[];
                      return medidata;
                    })
                    .concatMap(array => Observable.from(array))
                    .filter(medi => {
                            let searchTearmUpperCase = searchtearm.toUpperCase();
                            let mediNameUpperCase = medi.Name.toUpperCase();                       
                            return mediNameUpperCase.includes(searchTearmUpperCase);
                     })
                    .toArray();
      }
    

提交回复
热议问题