You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
check updateHotel() method in hotel.service.ts file and onUpdateHotel() method in hotel-edit.component.ts file. the problem is when i am trying to update a single hotel using onUpdateHotel() method i am getting error: "Missing 'hotels' id" what i am doing wrong?
hotel.service.ts file
import { Injectable } from '@angular/core';
import { HotelModel } from "./hotel.model";
import {Observable, of, Subject} from "rxjs/index";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {catchError, map, tap} from "rxjs/internal/operators";
@Injectable({
providedIn: 'root'
})
export class HotelService {
private hotelsUrl = 'api/hotels'; // URL to web api
private hotels: HotelModel[] = [];
constructor(private http: HttpClient) { }
httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' })
};
getHotels():Observable<HotelModel[]>{
return this.http.get<HotelModel[]>(this.hotelsUrl).pipe(
catchError(this.handleError<HotelModel[]>('get hotels', []) )
)
}
getHotel(id: number | string){ // or you can go 2nd method which is just below
return this.getHotels().pipe(
map((hotels:HotelModel[]) => hotels.find(hotel => hotel.id === +id ))
);
}
updateHotelInDetailSection(hotel:HotelModel):Observable<any>{
return this.http.put(this.hotelsUrl, hotel, this.httpOptions).pipe(
catchError(this.handleError<any>('update hotel'))
)
}
updateHotel(id:number, hotel:HotelModel):Observable<any>{
const url = `${this.hotelsUrl}/${id}`;
return this.http.put<HotelModel>(url, hotel, this.httpOptions).pipe(
tap(updatedHotel => console.log('hotel updated', url)),
catchError(this.handleError<any>('updateHotel'))
)
}
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
console.error(error); // log to console instead
return of(result as T);
};
}
}
check updateHotel() method in hotel.service.ts file and onUpdateHotel() method in hotel-edit.component.ts file. the problem is when i am trying to update a single hotel using onUpdateHotel() method i am getting error: "Missing 'hotels' id" what i am doing wrong?
hotel.service.ts file
hotel-edit.component.ts file
The text was updated successfully, but these errors were encountered: