I would like to have the save method in the class itself, and I'm not getting it, I'm a beginner in the typeScript language.
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class Usuario {
http: Http;
nome: string;
apelido: string;
email: string;
tel: string;
senha: string;
salvar(usuario){
this.http.post("http://localhost:5000/users",JSON.stringify(usuario), {})
.toPromise()
.then(res => console.log(res.json().data))
.catch();
}
}
I get the error:
browser_adapter.js:84 ORIGINAL EXCEPTION: TypeError: Cannot read property 'post' of undefined