I'm in an angular course 4, but I'm using 6, it catches me well, but every now and then there are some things that do not roll, I managed to fix most, but there's one that's making me crazy, MAP in the search method. I would need to move forward with this because my CBT depends on this kkkk. Thanks in advance.
Top Component (where the search bar is)
import { Component, OnInit } from '@angular/core';
import { OfertasService } from '../ofertas.service';
import { Observable } from 'rxjs';
import { Oferta } from '../shared/oferta.model';
public pesquisa(termoDaPesquisa: string): void{
this.ofertas = this.ofertasService.pesquisaOferta(termoDaPesquisa)
this.ofertas.subscribe(
(ofertas: Oferta[]) => console.log(ofertas)
)
}
oferta.service.ts (where is the logic of the offers, where I will do the search)
import { Http } from '@angular/http';
import { Injectable } from '@angular/core';
import { Oferta } from './shared/oferta.model';
import { URL_API } from './app.api'
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
public pesquisaOferta(termo: string): Observable<Oferta[]> {
return this.http.get('${URL_API}?descricao_oferta_like=${termo}')
.pipe(map((resposta: any) => resposta.json()))
}
and the top component html
<input type="text" class="form-control" placeholder="Pesquise por ofertas..." #termoDaPesquisa (keyup)="pesquisa(termoDaPesquisa.value)"/>
And I'm going to show a print of the screen with the error!
EDIT: topo.component complete
import { Component, OnInit } from '@angular/core';
import { OfertasService } from '../ofertas.service';
import { Observable } from 'rxjs';
import { Oferta } from '../shared/oferta.model';
@Component({
selector: 'xyz-topo',
templateUrl: './topo.component.html',
styleUrls: ['./topo.component.css'],
providers: [OfertasService]
})
export class TopoComponent implements OnInit {
public ofertas: Observable<Oferta[]>
constructor(private ofertasService: OfertasService) { }
ngOnInit() {
}
public pesquisa(termoDaPesquisa: string): void{
this.ofertas = this.ofertasService.pesquisaOferta(termoDaPesquisa)
this.ofertas.subscribe(
(ofertas: Oferta[]) => console.log(ofertas)
)
}
}