Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable} from '@angular/core';
- import {HttpClient,HttpHeaders} from '@angular/common/http';
- @Injectable({
- providedIn: 'root'
- })
- export class PresupuestosService {
- //Url de mi tabla
- presURL = 'localhost/presupuesto.json';
- constructor(private http: HttpClient) {
- }
- postPresupuesto(presupuesto: any) {
- const newpres = JSON.stringify(presupuesto);
- const headers = new HttpHeaders({
- 'Content-Type': 'application/json'
- });
- return this.http.post(this.presURL,newpres,{headers});
- }
- }
- export class PresupuestoComponent implements OnInit {
- constructor(private presupuestoService: PresupuestosService) {
- }
- //Evento del boton Añadir presupuesto
- onSubmit() {
- this.presupuesto = this.savePresupuesto();
- this.presupuestoService.postPresupuesto( this.presupuesto );
- }
- savePresupuesto() {
- return {
- //Los valores de los campos del formulario
- proveedor: this.presupuestoForm.get('proveedor').value,
- fecha: this.presupuestoForm.get('fecha').value,
- concepto: this.presupuestoForm.get('concepto').value,
- base: this.presupuestoForm.get('base').value,
- tipo: this.presupuestoForm.get('tipo').value,
- iva: this.presupuestoForm.get('iva').value,
- total: this.presupuestoForm.get('total').value
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement