feat(hotel-details): add delete button and functionality
This commit is contained in:
parent
a069e2f630
commit
ee7a4c995f
@ -1,4 +1,5 @@
|
|||||||
@if (hotel != null) {
|
@if (hotel != null) {
|
||||||
<app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item>
|
<app-hotel-item [hotel]="hotel" [isDetail]="true"></app-hotel-item>
|
||||||
<app-hotel-form [hotel]="hotel"></app-hotel-form>
|
<app-hotel-form [hotel]="hotel"></app-hotel-form>
|
||||||
|
<button (click)="delete()">DELETE</button>
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,13 @@ export class HotelDetailsComponent implements OnInit {
|
|||||||
|
|
||||||
constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { }
|
constructor(private route: ActivatedRoute, private http: HttpClient, private router: Router) { }
|
||||||
|
|
||||||
|
delete(): void {
|
||||||
|
if (confirm("Are u sure u want to delete this hotel")) {
|
||||||
|
this.http.delete<Hotel>("/api/hotels/" + this.route.snapshot.paramMap.get("id")).subscribe();
|
||||||
|
this.router.navigate(["/"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const routeParams = this.route.snapshot.paramMap;
|
const routeParams = this.route.snapshot.paramMap;
|
||||||
const hotelId = routeParams.get("id");
|
const hotelId = routeParams.get("id");
|
||||||
|
Loading…
Reference in New Issue
Block a user