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

89
Visualizações
Why do we need to have two same ids in alert-component and alert-service

I am trying to implement alerts on my webpage. I have found some guides that go through how to create alerts in angular. Most of them are implementing it in the same way which makes me believe it's the way to go. What I don't understand is that all of those guides have an id in the alertComponent with the annotation @input

Alert-component.ts

@Input() id = 'default-alert';

Then we call the onAlert method and provide the id as an argument

this.alertSubscription = this.alertService.onAlert(this.id)

The alert-service.ts class have also a field called defaultId with the same value as alert-component

alert-service.ts

private defaultId = 'default-alert';

Then in the implementation of OnAlert method in alert-service we take the id we recieve in as an argument and assign it to the default id ? is this a common thing in angular? I don't understand

onAlert(id = this.defaultId): Observable<Alert> {
        return this.subject.asObservable().pipe(filter(x => x && x.id === id));
    }

I would appricate yours answers to help me understand. Thanks!

about 4 years ago · Juan Pablo Isaza
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