Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import {Injectable} from '@angular/core';
  2. import {HttpClient,HttpHeaders} from '@angular/common/http';
  3.  
  4. @Injectable({
  5. providedIn: 'root'
  6. })
  7. export class PresupuestosService {
  8. //Url de mi tabla
  9. presURL = 'localhost/presupuesto.json';
  10. constructor(private http: HttpClient) {
  11. }
  12.  
  13. postPresupuesto(presupuesto: any) {
  14. const newpres = JSON.stringify(presupuesto);
  15. const headers = new HttpHeaders({
  16. 'Content-Type': 'application/json'
  17. });
  18. return this.http.post(this.presURL,newpres,{headers});
  19. }
  20. }
  21.  
  22. export class PresupuestoComponent implements OnInit {
  23. constructor(private presupuestoService: PresupuestosService) {
  24. }
  25. //Evento del boton Añadir presupuesto
  26. onSubmit() {
  27. this.presupuesto = this.savePresupuesto();
  28. this.presupuestoService.postPresupuesto( this.presupuesto );
  29. }
  30. savePresupuesto() {
  31. return {
  32. //Los valores de los campos del formulario
  33. proveedor: this.presupuestoForm.get('proveedor').value,
  34. fecha: this.presupuestoForm.get('fecha').value,
  35. concepto: this.presupuestoForm.get('concepto').value,
  36. base: this.presupuestoForm.get('base').value,
  37. tipo: this.presupuestoForm.get('tipo').value,
  38. iva: this.presupuestoForm.get('iva').value,
  39. total: this.presupuestoForm.get('total').value
  40. };
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement