Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda