I want to apply console.log in the angular method, but I'm having trouble, I'm doing this;
export class CervejaService {
cervejasUrl = 'http://localhost:8080/cervejas';
constructor(private http: Http) { }
adicionar(cerveja: Cerveja): Promise<Cerveja> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this.cervejasUrl,
JSON.stringify(cerveja), { headers })
.toPromise()
.then(response => {
console.log(response.json());
});
}
}
But you are generating this error;
ERROR in src / app / cevejas / cerveza.service.ts (15,9): error TS2322: Type 'Promise' is not assignable to type 'Promise'. Type 'void' is not assignable to type 'Beer'.
How do I apply the console.log ?
The way it's here it works perfectly, and it's saving
adicionar(cerveja: Cerveja): Promise<Cerveja> {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return this.http.post(this.cervejasUrl,
JSON.stringify(cerveja), { headers })
.toPromise()
.then(response => response.json());
}
I would just like to know how to apply the console.log in the method.