Error trying to save to the bank with Angular

0

Please note the error message:

POST http://localhost:8080/cervejas 415 ()
scheduleTask @ zone.js:2975
ZoneDelegate.scheduleTask @ zone.js:407
onScheduleTask @ zone.js:297
ZoneDelegate.scheduleTask @ zone.js:401
Zone.scheduleTask @ zone.js:232
Zone.scheduleMacroTask @ zone.js:255
(anonymous) @ zone.js:3008
proto.(anonymous function) @ zone.js:1382
(anonymous) @ http.js:1640
Observable._trySubscribe @ Observable.js:172
Observable.subscribe @ Observable.js:160
(anonymous) @ Observable.js:286
ZoneAwarePromise @ zone.js:887
Observable.toPromise @ Observable.js:284
CervejaService.adicionar @ cerveja.service.ts:15
CevejasCadastroComponent.salvar @ cevejas-cadastro.component.ts:51
(anonymous) @ CevejasCadastroComponent.html:2
handleEvent @ core.js:13581
callWithDebugContext @ core.js:15090
debugHandleEvent @ core.js:14677
dispatchEvent @ core.js:9990
(anonymous) @ core.js:12332
schedulerFn @ core.js:4351
SafeSubscriber.__tryOrUnsub @ Subscriber.js:240
SafeSubscriber.next @ Subscriber.js:187
Subscriber._next @ Subscriber.js:128
Subscriber.next @ Subscriber.js:92
Subject.next @ Subject.js:56
EventEmitter.emit @ core.js:4319
NgForm.onSubmit @ forms.js:5763
(anonymous) @ CevejasCadastroComponent.html:2
handleEvent @ core.js:13581
callWithDebugContext @ core.js:15090
debugHandleEvent @ core.js:14677
dispatchEvent @ core.js:9990
(anonymous) @ core.js:10611
(anonymous) @ platform-browser.js:2628
ZoneDelegate.invokeTask @ zone.js:421
onInvokeTask @ core.js:4744
ZoneDelegate.invokeTask @ zone.js:420
Zone.runTask @ zone.js:188
ZoneTask.invokeTask @ zone.js:495
invokeTask @ zone.js:1536
globalZoneAwareCallback @ zone.js:1562
erro-handler.service.ts:16 Ocorreu um erro Response {_body: "", status: 415, ok: false, statusText: "OK", headers: Headers, …}

He is saying that the error is in this code:

import { Cerveja } from './../core/model';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';

@Injectable()
export class CervejaService {

  cervejasUrl = 'http://localhost:8080/cervejas';

  constructor(private http: Http) { }

  adicionar(cerveja: Cerveja): Promise<Cerveja> {
        return this.http.post(this.cervejasUrl,
        JSON.stringify(cerveja))
      .toPromise()
      .then(response =>  response.json());
  }
}

According to this error message
BeerService.adding @ cerveza.service.ts: 15

To be more exact in this line:

.toPromise()

I think my add method is implementing wrong, how can I fix it?

    
asked by anonymous 17.01.2018 / 12:46

0 answers