I've got a component which goes out and makes an http request to get some data. The response could include errors from the request which I want to display within my application using a seperate error component/service/view.
I've got my components housed in my app.component.html view like:
<div>
<app-error *ngIf="// check if endpoint returned errors, if yes, show"></app-error>
<app-endpoint></app-endpoint>
</div>
I'm unsure how to get data from the endpoint component (where the errors will enter my application) into the error component and view.
For examples sake, this is logically what I'd want to happen when the EndpointComponent tries to get data:
endpoint.component.ts
export class EndpointComponent
{
constructor(private errorService: ErrorService){ }
getData(){
this.endpointService.get().subscribe(
response => checkError(response) // check and push to my error component if it exists)
...
error.service.ts
export class ErrorService
{
public pushErrors(error: string) {
// In here would be the code to push this error
// to error.component.ts / error.component.html
}
...
error.component.html
<div class="alert alert-danger">
<ul *ngFor="let error of errors">
<li>{{error}}</li>
</ul>
</div>
I'm unsure how to fill my error view with the error sent back within my endpoint component. Since this view would only ever be populated if errors exist within my other components response, I'm not sure how we tell our application to fill the elements with the error data.