Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 11, 2019 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/d90a0e2802df49b6d5188be761c59d49 to your computer and use it in GitHub Desktop.
Save parzibyte/d90a0e2802df49b6d5188be761c59d49 to your computer and use it in GitHub Desktop.
import { Component } from "@angular/core";
import { PersonasService } from "./personas.service";
import {Persona} from "./persona"
@Component({
selector: "my-app",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.css"]
})
export class AppComponent {
respuesta = {};
constructor(private personasService: PersonasService) {}
probarGet() {
this.respuesta = { mensaje: "Cargando..." };
this.personasService
.obtener()
.subscribe((personas: Persona) => {
this.respuesta = personas;
console.log(personas);
});
}
probarPost() {
let persona = new Persona("John Galt", 21);
this.respuesta = { mensaje: "Cargando..." };
this.personasService.registrar(persona).subscribe(datos => {
this.respuesta = datos;
});
}
probarPut() {
let persona = new Persona("Dagny Taggart", 19);
this.respuesta = { mensaje: "Cargando..." };
this.personasService.actualizar(persona).subscribe(datos => {
this.respuesta = datos;
});
}
probarDelete() {
let idPersona = 281196;
this.respuesta = { mensaje: "Cargando..." };
this.personasService.eliminar(idPersona).subscribe(datos => {
this.respuesta = datos;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment