我只想使用http方法从Firebase数据库中删除一条记录并更新一条记录。但是,有一种方法可以从数据库中删除整个记录。我不想删除整个记录。
我尝试了以下方法:
deleteJourney(journeyId : string) : Observable<void>
{
return this.httpclient.delete<void>(`${this.baseUrl}/${journeyId}`).pipe(catchError(this.handleError));
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable, throwError } from 'rxjs';
import { HttpErrorResponse } from '@angular/common/http';
import { Journey } from './Model/journey.model';
import { catchError, delay } from 'rxjs/operators';
@Injectable()
export class JourneyService{
private journeys : Journey[] = [];
baseUrl= 'https://ticket-management12345.firebaseio.com/journey.json';
constructor(private httpclient : HttpClient )
{ }
private handleError(errorResponse : HttpErrorResponse){
if(errorResponse.error instanceof ErrorEvent){
console.error('Client Side Error :', errorResponse.error.message)
}
else {
console.error('server Side Error :', errorResponse.error)
}
return throwError('There is issue in service, we are working on it');
}
getJourney(): Observable<Journey[]>{
return this.httpclient.get<Journey[]>(this.baseUrl).pipe(catchError(this.handleError));
}
addJourney(journey: Journey) : Observable<Journey>{
return this.httpclient.post<Journey>(this.baseUrl, journey).pipe(catchError(this.handleError));
}
// below 3 functions are not working
updateJourney(journey: Journey) : Observable<void>
{
return this.httpclient.patch<void>(`${this.baseUrl}/${journey.id}`, journey ,{
headers: new HttpHeaders({
'Content-Type' : 'application/json'
})
}).pipe(catchError(this.handleError));
}
getJourneyById(journeyId : number) : Observable<Journey>
{
return this.httpclient.get<Journey>(`${this.baseUrl}/${journeyId}`).pipe(catchError(this.handleError));
}
deleteJourney(journeyId : string) : Observable<void>
{
return this.httpclient.delete<void>(`${this.baseUrl}/${journeyId}`).pipe(catchError(this.handleError));
}
}
我希望一条记录会被更新/删除。