Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Searching in in-memory DB in Angular

I have an in-memory DB in angular

createDb(){
    let Data= [
      {id:1 , ProviderCode: '9W-', ProviderName: 'Jet Airways', ProviderType: 'Domestic' },
      {id:2 , ProviderCode: 'EK-', ProviderName: 'Emirates', ProviderType: 'International' },
    ];
    return {Data};
  }

and I have specified CRUD operations in separate service

 public getAllAirlines(){ 
       return this.httpClient.get(this.SERVER_URL + 'Data');
  }

  public getAirlines(ProviderType: String){
       return this.httpClient.get(`${this.SERVER_URL + 'Data'}/${ProviderType}`); 
  }
  public createAirlines(data: {ProviderCode: String, ProviderName: String, ProviderType: String}){
      return this.httpClient.post(`${this.SERVER_URL + 'Data'}`,data );
  }

  public deleteAirlines(AirlineId: String){
      return this.httpClient.delete(`${this.SERVER_URL + 'Data'}/${AirlineId}`);
  }
  public updateAirlines (data: {ProviderCode: String, ProviderName: String, ProviderType: String}) {
    return this.httpClient.put(`${this.SERVER_URL + 'Data'}/${data.ProviderCode}/${data.ProviderType}`, data);
  }

I have a Delete airline component, which has a form having details as ProviderCode and ProviderType to delete. To delete the record I need to retrieve the ID from the DB and I am unable to do that. Same case with update functionality. Please suggest me ways to do that.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

This function:

getAllAirlines(){ 
  return this.httpClient.get(this.SERVER_URL + 'Data');
}

Will return you an observable.

In your component you can subscribe to it and that will get you all the Airline objects with their id.

Writing the function fullout might help you with understanding:

getAllAirlines(): Observable<Airline[]>{ 
  return this.httpClient.get<Airline[]>(this.SERVER_URL + 'Data');
}

Let me also give an example of how to get the data from this request.

In your "delete-airline.component.ts":

airlines: Airline[] = []
...
constructor(
  private separateService: SeparateService
) { }

ngOnInit():void {
  this.separateService.getAllAirlines().subscibe(
    data => this.airlines = data
  )
}

Then you can just loop over the items in your airlines array and use their id values...

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!