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!