Question
Angular Signals: How to trigger an effect based on a signal without using its value?
I'm working with Angular and trying to use signals within an effect()
. My goal is to trigger an action when a specific signal changes, but the action itself doesn't need the signal's value.
For example, I have an isAuthorized
signal, and I want to call fetchCars()
whenever the authorization status changes, but fetchCars()
doesn't need to use the isAuthorized value.
constructor() {
effect(() => {
const isAuthorized = this.authService.userAuthorized();
// This function doesn't use the value of isAuthorized anyway.
this.fetchCars();
});
}
It works but it's a bit odd to assign isAuthorized
to a constant without actually using it. Is there a more correct or elegant way to achieve this?
Angular Version: 18.0.1