Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

88
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda