The version I use is Angular 7, because it has different things, but I’ll leave my code for you to take a look and take a test.
import { Injectable } from '@angular/core';
import { baseurl } from '../../../src/app/baseurl/baseurl';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Topicos } from '../interface/topicos';
@Injectable({
providedIn: 'root'
})
export class TopicosService {
constructor(private http: HttpClient) { }
getList():Observable<Topicos[]> { // Pasta/Controller.php/função
const url = `${baseurl.base_url}api_angular/topicos/topicos`;
return this.http.get<Topicos[]>(url);
}
getId(id: any):Observable<Topicos> {
const url = `${baseurl.base_url}api_angular/topicos/topicos/${id}`;
return this.http.get<Topicos>(url);
}
create(topico: Topicos):Observable<Topicos> {
const url = `${baseurl.base_url}api_angular/topicos/topicos`;
const header = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
const body = 'nome_topico=' + topico.nome_topico +
'&descricao_topico=' + topico.descricao_topico +
'&aprova=' + topico.aprova +
'&ativo=' + topico.ativo +
'&conclui_solicitacao=' + topico.conclui_solicitacao +
'&inconformidade=' + topico.inconformidade +
'&inconformidade_tipo=' + topico.inconformidade_tipo +
// '&servico=' + topico.servico +
'&id_setor=' + topico.id_setor +
'&id_grupo=' + topico.id_grupo +
'&id_usuario=' + topico.id_usuario +
'&destino=' + topico.destino
;
return this.http.post<Topicos>(url, body, {headers: header});
}
update(topico: Topicos):Observable<Topicos> {
const url = `${baseurl.base_url}api_angular/topicos/topicos/${topico.id_topico}`;
const header = new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded');
const body = 'id_topico=' + topico.id_topico +
'&nome_topico=' + topico.nome_topico +
'&descricao_topico=' + topico.descricao_topico +
'&aprova=' + topico.aprova +
'&ativo=' + topico.ativo +
'&conclui_solicitacao=' + topico.conclui_solicitacao +
'&inconformidade=' + topico.inconformidade +
'&inconformidade_tipo=' + topico.inconformidade_tipo +
// '&servico=' + topico.servico +
'&id_setor=' + topico.id_setor +
'&id_grupo=' + topico.id_grupo +
'&id_usuario=' + topico.id_usuario +
'&destino=' + topico.destino
;
return this.http.put<Topicos>(url, body, {headers: header});
}
delete(id_topico: number):Observable<Topicos> {
const url = `${baseurl.base_url}api_angular/topicos/topicos/${id_topico}`;
return this.http.delete<Topicos>(url);
}
}
guy checks if you step right the path of that 'oioi.json' it is on the same level of your Component? check that there
– user51231