se agrego el modificar
This commit is contained in:
@@ -1,12 +1,33 @@
|
|||||||
<table *ngIf="restaurante">
|
<table class="table" *ngIf="restaurante" border="1">
|
||||||
|
<thead>
|
||||||
<tr >
|
<tr >
|
||||||
<td>id</td><td>nombre</td><td>creacion</td><td>modificacion</td>
|
<td>id</td><td>nombre</td><td>creacion</td><td>modificacion</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
<tr *ngFor="let r of restaurante.data">
|
<tr *ngFor="let r of restaurante.data">
|
||||||
<td>{{r.id}}</td>
|
<td>{{r.id}}</td>
|
||||||
<td>{{r.nombre}}</td>
|
<td>{{r.nombre}}</td>
|
||||||
<td>{{r['created_at']}}</td>
|
<td>{{r['created_at']}}</td>
|
||||||
<td>{{r['updated_at']}}</td>
|
<td>{{r['updated_at']}}</td>
|
||||||
</tr>
|
|
||||||
</table>
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
nombre:<input type="text" [(ngModel)]="agre.nombre">
|
||||||
|
</p>
|
||||||
|
<p><button (click)="agregarRes()">agregar</button></p>
|
||||||
|
<p><button (click)="eliminarRes('6205091c-f172-424e-908c-f3c4bde39a9b')">elimiminar</button></p>
|
||||||
|
<p><button (click)="modificarRes('59323ad5-b0e5-45a2-8a2b-696f275ef209')">modificar</button></p>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@ export class AgregarResComponent implements OnInit {
|
|||||||
|
|
||||||
restaurante: any;
|
restaurante: any;
|
||||||
|
|
||||||
|
agre={
|
||||||
|
nombre:null
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
constructor(private restaurantServ : RestaurantesService) { }
|
constructor(private restaurantServ : RestaurantesService) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -19,6 +24,22 @@ export class AgregarResComponent implements OnInit {
|
|||||||
recuperartodos(){
|
recuperartodos(){
|
||||||
this.restaurantServ.mostrarTodosRes().subscribe(result => this.restaurante = result);
|
this.restaurantServ.mostrarTodosRes().subscribe(result => this.restaurante = result);
|
||||||
}
|
}
|
||||||
|
agregarRes(){
|
||||||
|
this.restaurantServ.agregar(this.agre).subscribe(this.recuperartodos)
|
||||||
|
}
|
||||||
|
eliminarRes(id:any){
|
||||||
|
console.log(id);
|
||||||
|
this.restaurantServ.eliminar(id).subscribe()
|
||||||
|
|
||||||
|
}
|
||||||
|
modificarRes(id:any){
|
||||||
|
console.log(id,this.agre)
|
||||||
|
|
||||||
|
this.restaurantServ.modificar(id,this.agre).subscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hayregistro(){
|
hayregistro(){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import {HttpClient} from "@angular/common/http";
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -14,4 +14,22 @@ export class RestaurantesService {
|
|||||||
mostrarTodosRes(){
|
mostrarTodosRes(){
|
||||||
return this.http.get(`${this.url}/restaurantes`);
|
return this.http.get(`${this.url}/restaurantes`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
agregar(AgreRestaurant:any){
|
||||||
|
const headers: HttpHeaders = new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
return this.http.post(`${this.url}/restaurantes`, JSON.stringify(AgreRestaurant),{ headers: headers });
|
||||||
|
}
|
||||||
|
eliminar(codigo:any){
|
||||||
|
return this.http.delete(`${this.url}/restaurantes/${codigo}`);
|
||||||
|
}
|
||||||
|
modificar(codigo:any,ModificarRes:any){
|
||||||
|
const headers: HttpHeaders = new HttpHeaders({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
return this.http.put(`${this.url}/restaurantes/${codigo}`, JSON.stringify(ModificarRes),{ headers: headers });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user