Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

198
Vistas
Search data in Observable

I'd like to have a search input, that display the result on keypress. At the moment, this is what I have :

mylist: Observable<MyData[]>;
term = new FormControl();
    ngOnInit() {
        this.mylist = this.term.valueChanges
                    .debounceTime(400)
                    .distinctUntilChanged()
                    .switchMap(term => this.searchData(term));
    }

    searchData(valueToSearch:string){
        if(valueToSearch == ''){
            this.channels = MyData.find();
        }
        return MyData.find({'title':new RegExp(valueToSearch)});
    }

It works quite well, but I have trouble to initialize "mylist", and I think my method isn't performant at all.

Basically, I want when my component is initialize, that:

this.mylist = MyData.find();

And on keypress, I want my search to be done on this.mylist, to avoid doing too much request. Is it possible ? I hope I'm clear.

Thanks by advance guys.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You must subscribe to the mapped data. Modify to the below code

this.term.valueChanges
    .debounceTime(400)
    .distinctUntilChanged()
    .switchMap(term => this.searchData(term))
    .subscribe((result) => {
            this.mylist = result
        });;

@Julia is correct , modify your searchData() function as below

searchData(valueToSearch:string):Observable<any> {
        if(valueToSearch == ''){
            this.channels = MyData.find();
        }
        return <Observable<any>>MyData.find({'title':new RegExp(valueToSearch)});
    }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda