How to return observable from subscribe

后端 未结 6 1849
萌比男神i
萌比男神i 2020-12-04 15:16

I\'m trying to return an observable when I get a certain value in a subscriber, but I fail miserably.

This is the code:

canActivate(route: Activated         


        
6条回答
  •  伪装坚强ぢ
    2020-12-04 15:58

    Couldn't we just use pipe with map from import { map } from 'rxjs/operators';?

    import { map } from 'rxjs/operators';
    
    @Injectable({
      providedIn: 'root'
    })
    export class SearchHostService {
      constructor(private http: HttpClient) { }
      searchForHosts(searchString: string): Observable {
        const res = >this.http.get('./assets/host-users.json');
        const result = res.pipe(
          map(val =>
            val.filter(emp => emp.displayName.toLowerCase().startsWith(searchString))
          ));
        return result;
      }
    }
    

提交回复
热议问题