I have a writeable signal in a service:
<code>private errorEntries: WritableSignal<ErrorEntry[]> = signal<ErrorEntry[]>([])
</code>
<code>private errorEntries: WritableSignal<ErrorEntry[]> = signal<ErrorEntry[]>([])
</code>
private errorEntries: WritableSignal<ErrorEntry[]> = signal<ErrorEntry[]>([])
I have a getter in the service:
<code> getErrorEntries(): WritableSignal<ErrorEntry[]> {
return this.errorEntries;
}
</code>
<code> getErrorEntries(): WritableSignal<ErrorEntry[]> {
return this.errorEntries;
}
</code>
getErrorEntries(): WritableSignal<ErrorEntry[]> {
return this.errorEntries;
}
and anode methode:
<code> public addError(error: any): void {
const timestamp = new Date().toISOString();
const message = error.message || error.toString();
const stack = error.stack || 'No stack trace available';
const route = this.router.url;
const errorEntry: ErrorEntry = { timestamp, message, stack, route };
this.errorEntries.update((entries) => [...entries, errorEntry]);
}
</code>
<code> public addError(error: any): void {
const timestamp = new Date().toISOString();
const message = error.message || error.toString();
const stack = error.stack || 'No stack trace available';
const route = this.router.url;
const errorEntry: ErrorEntry = { timestamp, message, stack, route };
this.errorEntries.update((entries) => [...entries, errorEntry]);
}
</code>
public addError(error: any): void {
const timestamp = new Date().toISOString();
const message = error.message || error.toString();
const stack = error.stack || 'No stack trace available';
const route = this.router.url;
const errorEntry: ErrorEntry = { timestamp, message, stack, route };
this.errorEntries.update((entries) => [...entries, errorEntry]);
}
I have an effect in another component.
<code> showExclamationMark = false;
constructor(private globalErrorHandlerService: GlobalErrorHandlerService) {
effect(() => {
const errors = this.globalErrorHandlerService.getErrorEntries()();
this.showExclamationMark = errors.length > 0;
});
}
</code>
<code> showExclamationMark = false;
constructor(private globalErrorHandlerService: GlobalErrorHandlerService) {
effect(() => {
const errors = this.globalErrorHandlerService.getErrorEntries()();
this.showExclamationMark = errors.length > 0;
});
}
</code>
showExclamationMark = false;
constructor(private globalErrorHandlerService: GlobalErrorHandlerService) {
effect(() => {
const errors = this.globalErrorHandlerService.getErrorEntries()();
this.showExclamationMark = errors.length > 0;
});
}
The effect works fine. But the errors.length always empty, why?
I don’t see what I missed.
I noticed during debug in the service one of the errorEntries property
has a value:
<code> SYMBOL(Signal):
value: Array(1)
</code>
<code> SYMBOL(Signal):
value: Array(1)
</code>
SYMBOL(Signal):
value: Array(1)
contains a value.