Boa noite! Estou recendo esse erro ao clicar em novo animal.
animais.service.ts
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { catchError, map, Observable, of, throwError } from 'rxjs';
import { environment } from 'src/environments/environment';
import { TokenService } from '../autenticacao/token.service';
import { Animais, Animal } from './animais';
const API = environment.apiUrl;
const NOT_NODIFIED = '304';
@Injectable({
providedIn: 'root'
})
export class AnimaisService {
constructor(
private http: HttpClient,
private tokenService: TokenService
) { }
listaDoUsuario_old(nomeDoUsuario: string): Observable<Animais> {
const token = this.tokenService.retornaToken();
const headers = new HttpHeaders().append('x-access-token', token);
return this.http.get<Animais>(`${API}/${nomeDoUsuario}/photos`, {
headers,
});
}
buscaPorId_old (id: number): Observable<Animal> {
const token = this.tokenService.retornaToken();
const headers = new HttpHeaders().append('x-access-token', token);
return this.http.get<Animal>(`${API}/photos/${id}`, {
headers,
});
}
/**
* Após criar o interceptor o angular tratará o token e o
* header de forma transparente
*/
listaDoUsuario(nomeDoUsuario: string): Observable<Animais> {
return this.http.get<Animais>(`${API}/${nomeDoUsuario}/photos`);
}
buscaPorId (id: number): Observable<Animal> {
return this.http.get<Animal>(`${API}/photos/${id}`);
}
excluirAnimal (id: number): Observable<Animal> {
return this.http.delete<Animal>(`${API}/photos/${id}`);
}
curtir (id: number): Observable<boolean> {
return this.http.post(
`${API}/photos/${id}/like`,
{},
{observe: 'response'}
).pipe(
map(() => true),
catchError((error) => {
return error.status == NOT_NODIFIED ? of(false) : throwError(() => new Error(error));
})
);
}
upload (descricao: string, permiteComentario: boolean, arquivo: File) {
const formData = new FormData();
formData.append('description', descricao);
formData.append('allowComments', permiteComentario ? 'true' : 'false');
formData.append('imageFile', arquivo);
return this.http.post(`${API}/photos/upload`, formData, {
observe: 'events', reportProgress: true,
});
}
}
animais-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DetalheAnimalComponent } from './detalhe-animal/detalhe-animal.component';
import { ListaAnimaisComponent } from './lista-animais/lista-animais.component';
import { ListaAnimaisResolver } from './lista-animais/lista-animais.resolver';
import { NovoAnimalComponent } from './novo-animal/novo-animal.component';
const routes: Routes = [
{
path: '', component: ListaAnimaisComponent,
resolve: {
animais: ListaAnimaisResolver,
}
},
{ path: ':animalId', component: DetalheAnimalComponent },
{ path: 'novo', component: NovoAnimalComponent },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AnimaisRoutingModule { }